简体   繁体   English

得到“无法翻译。 以可翻译的形式重写查询”,.NET Corel 中的异常

[英]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.

相关问题 无法翻译 Orderby。 要么以可以翻译的形式重写查询 - Orderby could not be translated. Either rewrite the query in a form that can be translated 实体框架,Linq 查询抛出异常“无法翻译。要么以可以翻译的形式重写查询 - Entity Framework, Linq query is throwing exception "could not be translated. Either rewrite the query in a form that can be translated LINQ 无法翻译表达式。 要么以可以翻译的形式重写查询 - LINQ expression could not be translated. Either rewrite the query in a form that can be translated 错误 - 无法翻译 EF Core。 要么以可以翻译的形式重写查询 - ERROR - EF Core could not be translated. Either rewrite the query in a form that can be translated 无法翻译 LINQ 表达式。 要么以可以翻译的形式重写查询 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated 无法翻译 LINQ 表达式。 要么以可翻译的形式重写查询,要么切换到客户评估 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation 无法翻译 LINQ 表达式 g.Inner)'。 以可以翻译的形式重写查询 - The LINQ expression g.Inner)' could not be translated. Either rewrite the query in a form that can be translate 无法翻译 LINQ 表达式。 以可翻译的形式重写查询,或切换到客户端评估 EF Core 3.1 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1 要么以可翻译的形式重写查询,要么显式切换到客户端评估……通过插入对 &#39;AsEnumerable 的调用 - Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly… by inserting a call to 'AsEnumerable EF Core 如何以可翻译的形式重写查询 - EF Core how to rewrite the query in a form that can be translated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM