[英]Getting “could not be translated. Either rewrite the query in a form that can be translated”, exception in .NET Corel
I am working on a C# application.我正在开发一个 C# 应用程序。 I have to create a predicate for filtering data.
我必须创建一个谓词来过滤数据。 I have a model class
TissueItem
which has a property named ExpirationData
.我有一个 model class
TissueItem
,它有一个名为ExpirationData
的属性。 I have to get that data from TissueItem
where expiration date is less than or equal to number specified.我必须从到期日期小于或等于指定数字的
TissueItem
获取该数据。 My predicate expression is:我的谓词表达式是:
ExpressionStarter<TissueItem> predicate = PredicateBuilder.New<TissueItem>();
predicate = predicate.And(x =>
Convert.ToInt32((x.ExpirationDate.Value - DateTime.Today).TotalDays)
<= inventorySearchFilterModel.ExpirationStatus);
When i pass this predicate to get the data, i am getting the following exception:当我通过这个谓词来获取数据时,我得到了以下异常:
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'.
What can be the possible issue.可能是什么问题。 I am using .NET Core 3.1.
我正在使用 .NET Core 3.1。
Try this variant.试试这个变种。 Looks like EFC do not handle
Timestamp.TotalDays
.看起来 EFC 不处理
Timestamp.TotalDays
。
var predicate = PredicateBuilder.New<TissueItem>();
predicate = predicate.And(x =>
EF.Functions.DateDiffDay(x.ExpirationDate.Value, DateTime.Today)
<= inventorySearchFilterModel.ExpirationStatus);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.