You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query: Query containing subquery with annonymous type fails to translate to server #7844
Compiling query model:
'from Employee e in
(from Employee <generated>_1 in DbSet<Employee>
select <generated>_1)
.Take(__p_0)
from <>f__AnonymousType15<Order> o in
from Order o in
(from Order <generated>_1 in DbSet<Order>
select <generated>_1)
.Take(1000)
select new <>f__AnonymousType15<Order>(o)
where (Nullable<int>) e.EmployeeID == o.o.EmployeeID
select new <>f__AnonymousType14<<>f__AnonymousType13<Employee>, <>f__AnonymousType15<Order>>(
new <>f__AnonymousType13<Employee>(e),
o
)'
which is being optimized into this now
'from Employee e in
(from Employee <generated>_1 in DbSet<Employee>
select <generated>_1)
.Take(__p_0)
from <>f__AnonymousType15<Order> o in
(from Order o in DbSet<Order>
select new <>f__AnonymousType15<Order>(o))
.Take(1000)
where (Nullable<int>) e.EmployeeID == o.o.EmployeeID
select new <>f__AnonymousType14<<>f__AnonymousType13<Employee>, <>f__AnonymousType15<Order>>(
new <>f__AnonymousType13<Employee>(e),
o
)'
Since the AdditionalFromClause has anonymous type projection, we fail to translate the whole query as cross join.
The root cause here seems to be QueryParser. Even though MainFromClause & AdditionalFromClause both have same structure, the where predicate for MainFromClause is optimized from new { e }.e.EmployeeID to e.EmployeeId. While same optimization does not happen for AdditionalFromClause.
@smitpatel@anpete this is not a problem with Re-Linq. It's just that once you moved the selector down into the subquery, the subquery now gets flagged for RequiresClientProjection unnecessarily. I just locally cherry-picked #7843 on top of my other PR #7767 and it is resolved.
@tuespetre - Good to know that #7767 fixes this. I did not mean that this is issue in Re-Linq. Though certain an optimization which Re-Linq can expand. 3 components - ReLinq QueryParser, EF QM optimizations & EF Query translations are involved in this translation. So we can apply fix at any place. It is the same difference that instead of lifting subqueries in translation we lifted in QueryOptimizer. If Re-Linq generates more optimized QM then its good for us. If not then we improve translation logic to deal with such cases. (Exactly what you are doing in #7767. Thanks.)
Just wanted to make sure that we have issue tracking the test that we should do something to enable translation to Server.
changed the title [-]Query: Test Where_subquery_anon fails to translate to server[/-][+]Query: Query containing subquery with annonymous type fails to translate to server[/+]on May 10, 2017
Activity
smitpatel commentedon Mar 10, 2017
@anpete - Should we report this to Re-Linq or try to work-around on our side?
tuespetre commentedon Mar 10, 2017
@smitpatel @anpete this is not a problem with Re-Linq. It's just that once you moved the selector down into the subquery, the subquery now gets flagged for
RequiresClientProjectionunnecessarily. I just locally cherry-picked #7843 on top of my other PR #7767 and it is resolved.See: tuespetre@4933293
smitpatel commentedon Mar 10, 2017
@tuespetre - Good to know that #7767 fixes this. I did not mean that this is issue in Re-Linq. Though certain an optimization which Re-Linq can expand. 3 components - ReLinq QueryParser, EF QM optimizations & EF Query translations are involved in this translation. So we can apply fix at any place. It is the same difference that instead of lifting subqueries in translation we lifted in QueryOptimizer. If Re-Linq generates more optimized QM then its good for us. If not then we improve translation logic to deal with such cases. (Exactly what you are doing in #7767. Thanks.)
Just wanted to make sure that we have issue tracking the test that we should do something to enable translation to Server.
Refactor RelationalProjectionExpressionVisitor
Refactor RelationalProjectionExpressionVisitor
Refactor RelationalProjectionExpressionVisitor
Refactor RelationalProjectionExpressionVisitor
[-]Query: Test Where_subquery_anon fails to translate to server[/-][+]Query: Query containing subquery with annonymous type fails to translate to server[/+]