We're using EFCore 3.1 and trying to build a query using Exists by means of .Any() which spans 2 properties.
var selectionCriteria = someHugeList.Select(sh => new { sh.Id, sh.StatusCode }).ToList()
var resultsQry = _myContext.SomeClass
.Include(sc => sc.DetailRecords)
.Where(sc => selectionCriteria.Any(crit => crit.Id == sc.Id
&& crit.StatusCode == sc.StatusCode));
var results = await resultsQry.ToListAsync()
When running this query (even with a small amount (5 items) of selection criteria items it provides the following error message;
System.InvalidOperationException: LINQ expression 'DbSet .Where(c => __selectionCriteria_0 .Any(crit => crit.Id == sc.Id && crit.StatusCode == sc.StatusCode))' 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(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'
Seems the problem resides in the fact that there are 2 properties included in the .Any clause. A where exists in sql normally can do this without problem. EFCore seems to find this difficult.
Does anyone have an idea on how to solve this?