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

On the newest version of entity framework core it throws errors #14

Open
inf9144 opened this issue Mar 3, 2023 · 2 comments
Open

On the newest version of entity framework core it throws errors #14

inf9144 opened this issue Mar 3, 2023 · 2 comments

Comments

@inf9144
Copy link

inf9144 commented Mar 3, 2023

Description

If you try to optimize a query on a DbSet it throws:

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

or

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

both at:

ExpressionOptimizer.visitchilds(Expression e)
ExpressionOptimizer.visit'(Expression exp)
ExpressionOptimizer.visitchilds(Expression e)
ExpressionOptimizer.visit'(Expression exp)
ExpressionOptimizer.visit(Expression exp)
IQueryProvider.CreateQuery[TElement](Expression expression)
ExpandableIncludableQueryProvider`1.CreateQuery[TElement](Expression expression)

Repro steps

.NET 7, EF Core 7, One simple Table with DbSet and a Query on it.
Used LinqKit to inject the optimizer into the IQueryable.

scottksmith95/LINQKit#172

@Thorium
Copy link
Owner

Thorium commented Mar 7, 2023

Thanks for reporting this. It seems they've added new Extension type to the enum to Linq expression trees, so this fails to handle how to visit them: https://github.com/Thorium/Linq.Expression.Optimizer/blob/master/src/Code/ExpressionOptimizer.fs#L453

Looking into EF core code, they seem to not have type or way to visit, but some kind of "skip" for "Extension"s, e.g. here:
https://github.com/dotnet/efcore/blob/main/src/EFCore/Query/ExpressionEqualityComparer.cs#L344

Also LinqKit doesn't know how to visit those:
https://github.com/scottksmith95/LINQKit/blob/d2af65394568e7555794e50cf30c9e84993dfb3b/src/LinqKit.Core/ExpressionVisitor.cs#L109

Hmm. Sounds non-optimal, to say "in case of extension, we have to just skip everything", because user has no visibility what is going on. If this is the direction that has to be taken, then something like this could help
image

Thorium added a commit that referenced this issue Mar 7, 2023
@Thorium
Copy link
Owner

Thorium commented Mar 7, 2023

There is now 1.0.15 in Nuget, let me know if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants