LINQKit icon indicating copy to clipboard operation
LINQKit copied to clipboard

QueryOptimizer with EFCore?

Open AudriusButkevicius opened this issue 2 years ago • 5 comments

Not sure whether this should work or not, but I'm struggling to use the query optimizer with EFCore.

Seems that a simple query such as the following one fails:

_context.Items.Include(o => o.Parts).AsExpandable(ExpressionOptimizer.visit).Take(10);

Returns an error:

System.Exception: encountered unknown LINQ expression: Extension [Microsoft.EntityFrameworkCore.Query.QueryRootExpression]

Is this expected?

AudriusButkevicius avatar Mar 10 '22 23:03 AudriusButkevicius

same problem here :-(

https://github.com/Thorium/Linq.Expression.Optimizer/issues/14

inf9144 avatar Mar 03 '23 15:03 inf9144

There is a fix now released, hopefully that helps.

Thorium avatar Mar 08 '23 13:03 Thorium

@Thorium Should also this project be fixed?

StefH avatar Mar 08 '23 17:03 StefH

I thin LinqKit already "handles" the Extension case (or rather, ignores Extensions) and the problem was only with the Linq.Expression.Optimizer.

I don't know why EF Core suddenly needs extensions to ExpressionTrees. So I don't know if the ignoring is the correct design, but definitely it sounds a bit suspicious that we have the LINQ "language" (which was made mathematically properly originally) and then we have some extensions, probably for injecting something impure.

Thorium avatar Mar 08 '23 18:03 Thorium

I also don't know why.

I noticed that this new version works nicely with my efcore 6/7 example in this project: https://github.com/StefH/QueryInterceptor.Core

StefH avatar Mar 08 '23 22:03 StefH