Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

EF Core 3.1.x:

I would not like to load all products in memory, which below queries do! Guess what happen if i do have millions of products in table?

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

And below query throws The LINQ expression 'DbSet-Product- .Where(b => b.Name.Contains( value: "xxx", comparisonType: InvariantCultureIgnoreCase))' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().

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

Related Issue on github: #19087

Can anyone help me out. how to filter data with server side evaluation with ef core 3.1.x?

like image 585
Nimesh Vaghasiya Avatar asked May 20 '20 08:05

Nimesh Vaghasiya


1 Answers

EF Core does translate Contains for server-side evaluation - but not the overload that accepts StringComparison.InvariantCultureIgnoreCase (or any other StringComparison).

Closed issue here

like image 69
Nimesh Vaghasiya Avatar answered Nov 09 '22 10:11

Nimesh Vaghasiya