我有一个List
属性,我设置如下:
testCard.LstSummaries =
db.Summaries.Where(
x =>
(x.AID == aId || x.AInformation.RegNumber == aRegNumber) && DbFunctions.TruncateTime(x.Day) == DateTime.Today.Date &&
x.deleted == false).ToList();
然后我有条件声明:
if (testCard.LstSummaries.Count > 0)
{
if (
testCard.LstSummaries.All(
x =>
(x.AID == aId || // ERROR HAPPENS ON THIS LINE
x.AInformation.RegNumber == aRegNumber) &&
DbFunctions.TruncateTime(x.Day) == DateTime.Today.Date && x.deleted == false))
{
// .... do something
}
我收到错误:
只能从LINQ to Entities调用此函数。
我想避免多次调用数据库..此外testCard.LstSummaries
已经有我正在寻找的值..但如果我这样做:
if (testCard.LstSummaries.Count > 0)
{
if (
db.Summaries.All(
x =>
(x.AID == aId || // NO ERROR
x.AInformation.RegNumber == aRegNumber) &&
DbFunctions.TruncateTime(x.Day) == DateTime.Today.Date && x.deleted == false))
{
// .... do something
}
我觉得调用数据库是没有意义的,因为我会检索已经存储在testCard.LstSummaries
中的相同结果,但我无法调用.All()
,因为它&#39 ; s不是LINQ to Entities
。
有解决方法吗?
答案 0 :(得分:2)
问题在于DbFunctions.TruncateTime(x.Day),因为它在运行时被转换为sql。尝试不用它来检查。