Efcore: OrderBy: Could not be translated and will be evaluated locally.

Created on 23 Apr 2019  路  5Comments  路  Source: dotnet/efcore

Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'orderby [x].Id desc, EF.Property(?[x.Item]?, "Id") asc' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.

C:Users\SQ>dotnet --version
3.0.100-preview4-011223

EFCore => 3.0.0-preview4.19216.3

closed-could-not-reproduce customer-reported

All 5 comments

@blahblehblah, you have spotted good error which shows that your query can not be translated to SQL effectively. In previous versions of EF Core it was treated as warning by default - not now.
Check this article https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-3-0-preview-4/ - LINQ queries are no longer evaluated on the client. And I'm personally appreciate that, because app servers become more stable and developers are forced to learn SQL and how it works.

Also without exact LINQ query your issue can not be solved by anyone.

EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?

Steps to reproduce

Ideally include a complete code listing that we can run to reproduce the issue.
Alternatively, you can provide a project/solution that we can run.

BTW we're not just doing this to be mean :smile:... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we ask that folks give us a self contained way to reproduce an issue.

For a guide on submitting good bug reports, read Painless Bug Tracking.

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

I'm having this issue, too...

                  var readAgg = from r in booksDbContext.ReadBooks.AsNoTracking()
                      group r by r.BookId into grp
                      select new { grp.Key, Count = grp.Count() })
                      .OrderByDescending(g => g.Count)
                      .Take(count);

                   var results = await (from b in booksDbContest.Books.AsNoTracking()
                       join ag in readAgg
                       on b.Id equals ag.Key
                       select new BookItemModel
                       {
                           Name = b.Name,
                           Id = b.Id,
                           ReadCount = ag.Count,
                       })
                       .OrderByDescending(b => b.Count)
                       .ToArrayAsync();

and I got

warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'orderby [ag].Count desc' could not be translated and will be evaluated locally.

however, I can see it also prints

SELECT [t].[Key], [t].[Count], [l].[Name], [b].[Id]
FROM [Books] AS [b]
INNER JOIN (
SELECT [r].[BookId] AS [Key], COUNT(*) AS [Count]
FROM [ReadBooks] AS [r]
GROUP BY [r].[BookId]
) AS [t] ON [b].[Id] = [t].[Key]

and the performance is same as exec above script on sql server, looks like a false alarm


.net core sdk 2.1.701
ef core 2.1.8

@mchenx - This is a closed issue. Please file a new issue with repro code if you are hitting an error.

Was this page helpful?
0 / 5 - 0 ratings