EF.CompileQuery The LINQ expression could not be translated.
See original GitHub issueAsk a question
EF.CompileQuery((DbContext context) => context.Set<T>().AsNoTracking().Where(filter).ToList())(this); Message=The LINQ expression ‘DbSet<LhUser>() .Where(l => l.Id == 1) .ToList()’ 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’. I use the EF core 5.0.7,but the sdks is net core 3.1, Remember:
- Please make your question as clear and specific as possible.
- Please check that the documentation does not answer your question.
- Please search in both open and closed issues to check that your question has not already been answered.
Include your code
Usually the best way to ask a clear question and get a quick response is to show your code. Preferably, attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing.
Use triple-tick code fences for any posted code. For example:
Console.WriteLine("Hello, World!");
Include stack traces
Include the full exception message and stack trace for any exception you encounter.
Use triple-tick fences for stack traces. For example:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at SixFour.Sub() in C:\Stuff\AllTogetherNow\SixFour\SixFour.cs:line 49
at SixFour.Main() in C:\Stuff\AllTogetherNow\SixFour\SixFour.cs:line 54
Include verbose output
Please include verbose output when asking questions about the dotnet ef
or Package Manager Console tools.
Use triple-tick fences for tool output. For example:
C:\Stuff\AllTogetherNow\FiveOh>dotnet ef dbcontext list --verbose
Using project 'C:\Stuff\AllTogetherNow\FiveOh\FiveOh.csproj'.
...
Finding DbContext classes in the project...
Found DbContext 'BlogContext'.
BlogContext
Include provider and version information
EF Core version: Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 5.0) Operating system: IDE: (e.g. Visual Studio 2019 16.3)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Not opposing though
ToList
😉Note from triage: added a note to #14551 to consider when re-visiting compiled query API.