dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.8k stars 3.2k forks source link

Query: Anonymous type to constant comparison should be server eval'ed #14672

Open smitpatel opened 5 years ago

smitpatel commented 5 years ago
return AssertQuery<Customer>(
                isAsync,
                cs => cs.Where(
                    c => new
                    {
                        x = c.City
                    } == new
                    {
                        x = "London"
                    }));

It client evals because the constant is of type anonymous type which TypeMappingSource can never map. We need to be smart about identifying such pattern and deconstruct it. We do similar for joins already (or even for Where), when there are server correlated parameters which causes lack of ConstantExpression.

roji commented 2 years ago

Note: the above with an anonymous type, but the same applies also the ValueTuple/Tuple. For those, possibly consider row values when dealing with this (#26822, https://github.com/npgsql/efcore.pg/issues/2349) (i.e. the above could be rendered as (x, y) = (3, 4)).

PS Removing duplicate label