【发布时间】:2021-01-21 06:07:23
【问题描述】:
我正在开发一个 C# 应用程序。我必须创建一个谓词来过滤数据。我有一个模型类TissueItem,它有一个名为ExpirationData 的属性。我必须从 TissueItem 获取该数据,其中到期日期小于或等于指定的数字。我的谓词表达式是:
ExpressionStarter<TissueItem> predicate = PredicateBuilder.New<TissueItem>();
predicate = predicate.And(x =>
Convert.ToInt32((x.ExpirationDate.Value - DateTime.Today).TotalDays)
<= inventorySearchFilterModel.ExpirationStatus);
当我通过这个谓词来获取数据时,我得到了以下异常:
The LINQ expression 'DbSet<TissueItem>()
.Where(t => Convert.ToInt32((t.ExpirationDate.Value - DateTime.Today).TotalDays) <= __inventorySearchFilterModel_ExpirationStatus_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.
可能是什么问题。我正在使用 .NET Core 3.1。
【问题讨论】:
-
@YegorAndrosov nops
-
即使我删除“Convert.ToInt32”,它仍然会给出同样的错误
标签: c# .net-core entity-framework-core predicate