EF Core 3.1.x:无法翻译 LINQ 表达式。要么以可以翻译的形式重写查询

EF Core 3.1.x : The LINQ expression could not be translated. Either rewrite the query in a form that can be translated

EF 核心 3。1.x:

我不想加载内存中的所有产品,下面的查询可以! 猜猜如果我在 table 中有数百万种产品会怎样?

var products = context.Products.ToList();
products = products.Where(p => p.Name.Contains("xxx")).ToList();

下面的查询抛出 LINQ 表达式 'DbSet-Product- .Where(b => b.Name.Contains( 值:"xxx", comparisonType: InvariantCultureIgnoreCase))' 无法翻译。以可翻译的形式重写查询,或通过插入对 AsEnumerable()、AsAsyncEnumerable()、ToList() 或 ToListAsync() 的调用显式切换到客户端评估。

var products = context.Products.Where(p => p.Name.Contains("xxx", StringComparison.InvariantCultureIgnoreCase)).ToList();

github 上的相关问题:#19087

谁能帮帮我。如何使用 ef core 3.1.x?

通过服务器端评估过滤数据

EF Core 会为服务器端评估转换 Contains - 但不会转换接受 StringComparison.InvariantCultureIgnoreCase(或任何其他 StringComparison)的重载。

Closed issue here