-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Using Any() in projected query warns about client side evaluation #6953
Labels
Comments
The problem here is that AutoMapper introduces ToList() inside ProjectTo method. ToList forces client evaluation on everything that happens after it. Essentially the query that is produced is as follows: ctx.Customers.Select(c => new CustomerDto
{
CustomerTypeAccessRuleName = c.CustomerType.CustomerTypeAccessRule.Name,
CustomerTypeName = c.CustomerType.Name,
Addresses = c.Addresses.Select(a => new AddressDto { City = a.City, Street = a.Street }).ToList() // <- this ToList call is a problem
}).Where(c => c.Addresses.Any(a => a.City == "Berlin")); // <- this is client-evaled due to ToList call on Addresses Similar query but without AutoMapper: ctx.Customers.Select(c => new
{
CustomerTypeAccessRuleName = c.CustomerType.CustomerTypeAccessRule.Name,
CustomerTypeName = c.CustomerType.Name,
Addresses = c.Addresses.Select(a => new { City = a.City, Street = a.Street })
}).Where(c => c.Addresses.Any(a => a.City == "Berlin")); produces the following SQL: SELECT [c.CustomerType.CustomerTypeAccessRule].[Name], [c.CustomerType].[Name], [c].[Id]
FROM [Customers] AS [c]
INNER JOIN [CustomerTypes] AS [c.CustomerType] ON [c].[CustomerTypeId] = [c.CustomerType].[Id]
INNER JOIN [CustomerTypeAccessRules] AS [c.CustomerType.CustomerTypeAccessRule] ON [c.CustomerType].[CustomerTypeAccessRuleId] = [c.CustomerType.CustomerTypeAccessRule].[Id]
WHERE EXISTS (
SELECT 1
FROM (
SELECT [a0].[City], [a0].[Street]
FROM [Address] AS [a0]
WHERE [c].[Id] = [a0].[CustomerId]
) AS [t]
WHERE [t].[City] = N'Berlin') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
Code to reproduce:
Produces warnings:
The issue
The Where(x => x.Relation.Any()) query warns about client side evaluation when using projected query.
Further technical details
EF Core version: 1.1.0-preview1
Operating system: Windows 10
Visual Studio version: VS 2015
Other details about my project setup: Query is projected using AutoMapper.
The text was updated successfully, but these errors were encountered: