C# 使用DbFunctions时,我得到错误:指定的类型成员';日期';在LINQ to实体中不支持

C# 使用DbFunctions时,我得到错误:指定的类型成员';日期';在LINQ to实体中不支持,c#,.net,entity-framework,entity-framework-6,C#,.net,Entity Framework,Entity Framework 6,即使使用DbFunctions.TruncateTime var touches = analyticRepo.GetAll() .Where(x => DbFunctions.TruncateTime(x.DateCreated.Date) == report.DateCreated.Date); var test = touches.ToList(); 我得到这个错误: LINQ to实体中不支持指定的类型成员“日期”。 仅初始值设

即使使用
DbFunctions.TruncateTime

var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated.Date) == report.DateCreated.Date);
var test = touches.ToList();
我得到这个错误:

LINQ to实体中不支持指定的类型成员“日期”。 仅初始值设定项、实体成员和实体导航属性 支持


你知道如何解决这个问题吗。

你可以将日期向上拉到一个变量中:

var reportDate = report.DateCreated.Date;
var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated) == reportDate);
var test = touches.ToList();

当属性getter返回(可能是)修改的支持字段时,会引发此异常。例如,getter return _field.ToString().SubString(1,6)或类似于这些行的内容。from System.Data.EntityI在mscorlib.dll中出现“System.NotSupportedException”类型的异常,但未在用户代码中处理。其他信息:指定的类型成员“Date”在LINQ to Entities中不受支持。只支持初始值设定项、实体成员和实体导航属性。我不明白您在这里做了什么。除了在开头加一行外,代码是一样的。@GibboK抱歉,没有注意到第一部分的
日期。尝试编辑的版本。@DavidG我从lambda中将
report.DateCreated.Date
拉入一个变量。