Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Prevent client evaluation if query modifiers precede condition #7560

Closed
breyed opened this issue Feb 6, 2017 · 9 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@breyed
Copy link

breyed commented Feb 6, 2017

The warning RelationalEventId.QueryClientEvaluationWarning is issued if Include precedes a condition when queries are chained. Code like this will trigger the warning:

IQueryable<Customer> subQuery = ...
var query = subQuery.AsTracking().Include(...).Single(condition)

By contrast, code like this does not:

IQueryable<Customer> subQuery = ...
var query = subQuery.Where(condition).AsTracking().Include(...).Single()
@smitpatel
Copy link
Contributor

Can you post the warning text also?

@breyed
Copy link
Author

breyed commented Feb 7, 2017

Warning as error exception for warning 'RelationalEventId.QueryClientEvaluationWarning': The LINQ expression '([c].AccountNumber == __accountNumber_2)' could not be translated and will be evaluated locally. To suppress this Exception use the DbContextOptionsBuilder.ConfigureWarnings API. ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider.

@tuespetre
Copy link
Contributor

tuespetre commented Feb 7, 2017


I've ~~~written up~~~ copy-paste-modified some very basic tests that use `AsTracking().Include()` before `Single(predicate)`, could you give us an example of what your subquery looks like?

@breyed
Copy link
Author

breyed commented Feb 8, 2017

IQueryable<Customer> subQuery =
    from c in Db.Customers
    where c.BranchId == branchId
    orderby c.LastName, c.FirstName
    select c;

@smitpatel
Copy link
Contributor

smitpatel commented Feb 14, 2017

@breyed - Which version of EF are you using?
I tried reproducing this, I received warning in both cases. In one it says cannot translate the equality (which is inside Single()) and in second it says cannot translate Single(). The cause is Single call which needs client evaluation to throw exception.
Can you share your full queries and model classes for reproduction of the issue?

Scratch that. I got repro.

@smitpatel
Copy link
Contributor

The subquery has an orderby clause. In Sql you cannot have orderby inside a subquery. Therefore it fails to translate outer query and shows client eval warning.
In the case when where is before as tracking, the Re-Linq query parser flattens out the whole model so there is nothing other than Single() outside the subquery. If Where comes after AsTracking it cannot translate it to server.

@smitpatel
Copy link
Contributor

Verify this is fixed when #7613 is closed.

@smitpatel
Copy link
Contributor

@maumar - Assigning this should be fixed with lifting of order by.

@smitpatel smitpatel assigned maumar and unassigned smitpatel Apr 4, 2017
@maumar
Copy link
Contributor

maumar commented Apr 5, 2017

Fixed in f022d66

@maumar maumar closed this as completed Apr 5, 2017
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 5, 2017
@ajcvickers ajcvickers changed the title Server-side evaluation fails if query modifiers precede condition Query: Server-side evaluation fails if query modifiers precede condition May 9, 2017
@divega divega changed the title Query: Server-side evaluation fails if query modifiers precede condition Query: Prevent client evaluation if query modifiers precede condition May 9, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

6 participants