On the newest version of entity framework core it throws errors
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.
https://github.com/scottksmith95/LINQKit/issues/172
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

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