I have a simple LINQ expression:
public List<Project> GetCheckedProjects(List<PickedUp> displayCollection)
{
IQueryable<Project> query = _context.Projects
.OrderBy(project => project.CompletionDate)
.Where(project => displayCollection.Any(item => item.ProjectID == project.ProjectID))
.Include(project => project.TechnologiesProjects)
.ThenInclude(techproj => techproj.Technology);
return query.ToList();
}
that drops me an runtime exception:
'The LINQ expression 'DbSet .OrderBy(p => p.CompletionDate) .Where(p => __displayCollection_0 .Any(item => item.ProjectID == p.ProjectID))' 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.'
In this MSDN article it is mentioned, that in EF Core 3.x were breaking changes, and they prevent client evaluation. And
In such cases, you can explicitly opt into client evaluation by calling methods like AsEnumerable or ToList (AsAsyncEnumerable or ToListAsync for async). By using AsEnumerable you would be streaming the results, but using ToList would cause buffering by creating a list, which also takes additional memory.
In my case, when using AsEnumerable()
I am geting an exception:
IEnumerable does not contain a definition for 'Include' (...)
Also simple using ToList()
at very end of expression, like in this SO answer, does not bring any positive result.
In EF Core 2.x my LINQ works fine. How to walk around this problem?