我遇到 EntityFramework 无法将 DateTime.Date 转换为 SQL 的问题。我遵循了有关此问题的其他答案(特定错误:LINQ to Entities 中不支持指定的类型成员“日期”。),但问题仍然发生。我错过了什么?
var todayChanges = kbEntities.Changelogs.Where(c =>
EntityFunctions.TruncateTime(c.creationdate) == DateTime.Now.Date &&
(c.name == ChangelogBL.ChangeLogName.ChangedKB.ToString() ||
c.name == ChangelogBL.ChangeLogName.Imported.ToString())).ToList();
从 DateTime.Now.Date 中删除 .Date 并尝试这个,它应该可以工作。
var TodayChanges = kbEntities.Changelogs.Where(c => EntityFunctions.TruncateTime(c.creationdate) == EntityFunctions.TruncateTime(DateTime.Now) && (c.name == ChangelogBL.ChangeLogName.ChangedKB.ToString() || c.name == ChangelogBL.ChangeLogName.Imported.ToString())).ToList();