Upgrade to EF Core 10
EF Core 10 has been released, this is an issue to upgrade this provider.
There have been various changes to the API including requiring implementation of TranslateRightJoin.
Other compilation errors are as follows:
'QueryContext' does not contain a definition for 'ParameterValues'
'QueryCompilationContext' does not contain a definition for 'QueryParameterPrefix'
'ShapedQueryCompilingExpressionVisitor.InjectEntityMaterializers(Expression)' is obsolete: 'Use InjectStructuralTypeMaterializers instead.'
@roji any insights or references to changes you've had to make to Npgsql provider? I know that the label providers-beware exists in the EF Core repo, but it's not particularly helpful.
Hey @mguinness 👋
These changes don't affect any relational providers (like the PG one), but they indeed do affect non-relational ones like this one... I'm unfortunately traveling and and very busy this week, but I'm happy to help out to migrate next week!
Just off the bat though:
- QueryParameterPrefix has been removed since we simplified parameter names - they're no longer prefixed; you should be OK to just stop referencing that and simplify your parameters as well.
- ParameterValues has been renamed to Parameters, and is now a simple dictionary of string to object.
- InjectEntityMaterializers() should be replaceable as-is with a call to InjectStructuralTypeMaterializers(), as the obsoletion message suggests - that's for the full support of complex types (which aren't entity types) in 10.
Give all this a try and let me know where you're still struggling.
Thanks Shay, the explanations were very helpful. I've added a PR with the changes which hopefully you can review next week when you have more time. Appreciate your assistance!
@dualbios Do you want to add me as a collaborator to this repo so I can assign roji to the code review, or do you want to do that yourself?
Hi @mguinness, great idea. I added you as a collaborator to the repository. Many thanks for the help!
@roji Once you're able to look at the PR, I found an issue with this query.
var tst = "Username222";
var tmp = db.Users.Where(i => i.Username == tst).ToList();
It gives me the following exception which doesn't happen on the previous version of the provider using EF Core 9.
System.InvalidOperationException: 'The LINQ expression 'DbSet<User>()
.Where(u => u.Username == @tst)' could not be translated.
Any ideas? I can add this test to the PR if that would be helpful. Full stack trace below:
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.Translate(Expression expression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutorExpression[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass11_0`1.<ExecuteCore>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteCore[TResult](Expression query, Boolean async, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at FileBaseContext.Example.Program.Main()
I did some more digging and the issue occurs here:
https://github.com/dualbios/FileBaseContext/blob/27a9d85933c73aa046246580fad52d44ab554738/FileBaseContext/Infrastructure/Query/FileStoreQueryableMethodTranslatingExpressionVisitor.cs#L639
For the query, the .NET 9 methodCallExpression is:
{[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(u => (u.Username == __tst_0))}
For the .NET 10 version methodCallExpression is:
{[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(u => (u.Username == [Microsoft.EntityFrameworkCore.Query.QueryParameterExpression]))}
Then base VisitMethodCall will return !!! NotTranslated !!! in debugger.
OK, I see that QueryParameterExpression was introduced in https://github.com/dotnet/efcore/commit/cda7816. I've made the corresponding changes and will continue to test.
@mguinness yeah, you figured it out by yourself :) I did a general cleanup of how query parameters work: they were previously regular LINQ ParameterExpressions with a special name prefix, and are now a custom expression node type (QueryParameterExpression). Aside from removing the smelly name-based matching and making a very clear distinction between lambda parameters and query parameters, this allows us to also store metadata on query parameters which was impossible to do before.
Let me know if you're blocked on anything else.
Thanks for the explanation, I think that was the only blocker.
@dualbios I tested the updated provider with an existing application and there were no issues, so you can merge PR https://github.com/dualbios/FileBaseContext/pull/45 and publish the NuGet package when you're ready.
The new release has been published. @mguinness , @roji Thanks a lot!
Thanks Kostiantyn.
@roji - Are you planning to update the documentation for Database Providers with EF Core 10 compatibility?
@mguinness that's usually something that the provider maintainers do themselves - feel free to submit a PR to update that page!
Thanks, I've submitted a PR. Just a heads up that SqlServer, Sqlite, InMemory & Cosmos are still just showing 8, 9.
Thanks for that - I'll submit a PR for the built-in providers.