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

Unable to cast object of type 'Z.EntityFramework.Plus.CreateEntityConnection' to type 'Npgsql.NpgsqlConnection'. #708

Open
tomerpeled opened this issue Nov 18, 2021 · 11 comments
Assignees

Comments

@tomerpeled
Copy link

tomerpeled commented Nov 18, 2021

After upgrading to .NET Core 6 (with EFCore 6 update + EntityFramework-plus), I'm now getting the following exception when using the Plus lib:
System.InvalidCastException: Unable to cast object of type 'Z.EntityFramework.Plus.CreateEntityConnection' to type 'Npgsql.NpgsqlConnection'.
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlRelationalConnection.get_DbConnection()
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlRelationalConnection.get_CurrentAmbientTransaction()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.HandleAmbientTransactions()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.InitializeReader(Enumerator enumerator) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.<>c.b__19_0(DbContext _, Enumerator enumerator)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.MoveNext() at Z.EntityFramework.Plus.QueryFutureValue1.SetResult(DbDataReader reader)
at Z.EntityFramework.Plus.QueryFutureBatch.ExecuteQueriesAsync(CancellationToken cancellationToken)
at Z.EntityFramework.Plus.QueryFutureValue`1.ValueAsync(CancellationToken cancellationToken)

Any idea how can we solve it?

Thanks,
Tomer

@JonathanMagnan JonathanMagnan self-assigned this Nov 18, 2021
@JonathanMagnan
Copy link
Member

Hello @tomerpeled ,

Thank you for reporting, we will try to reproduce it.

Best Regards,

Jon


Sponsorship
Help us improve this library

Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@JonathanMagnan
Copy link
Member

Hello @tomerpeled ,

Thank again for reporting.

Unfortunately, it looks like that PostgreSQL started to cast the connection. So the trick we used to make this feature work doesn't longer work as it requires the same exact connection type as the original.

Unfortunately, we currently have no solution for this issue.

We will try to eventually look again at it but for now, we will consider this feature do not longer supports this provider as this is impossible for us to fix it with the current time we have.

@tomerpeled
Copy link
Author

Hi @JonathanMagnan,

Thanks for the update!
Understood, we will probably hold the. Net core upgrade for now, because we prefer the Futures feature above the new .Net core features :)

@pandarun
Copy link

Hello, @tomerpeled !

Did you find the alternative to Future queries? I also need them to implement total in pagination use case.

https://entityframework-plus.net/ef-core-query-future#paging

@tomerpeled
Copy link
Author

Hi @pandarun,

Unfortunately, there is no workaround for now...

@alexb5dh
Copy link

alexb5dh commented Feb 11, 2022

@JonathanMagnan do you think raising issue about this in Npgsql repo may help?

@JonathanMagnan
Copy link
Member

Hello @alexb5dh ,

Unfortunately no, the error happens here if I remind correctly: https://github.com/npgsql/efcore.pg/blob/cf4f23ecc271b3c9753600ec84a65c7d4053991d/src/EFCore.PG/Storage/Internal/NpgsqlRelationalConnection.cs#L81

It cast our custom connection into a NpgsqlConnection. We did too much internal "hack" on our side and the only good way to make everything work again is probably to fully re-write this feature. Unfortunately, it is hard to find enough time for doing it.

@Balogh-Andras
Copy link

Hi,

I have the same issue with .net6 upgrade. Are you working on this problem? Will we be able to upgrade to net6 sometime?

Thx,
Andrew

@JonathanMagnan
Copy link
Member

Hello @Balogh-Andras ,

Unfortunately, we don't have enough time at this moment to work on this problem.

Supporting EF Core 7 and re-writing our core code to support new features they bring is currently our priority.

We hope to eventually fix it, but like everyone's problem, time is missing, so we currently prioritize development. This one is not easy to fix and ask us to rewrite most of it to support PostgreSQL and Oracle.

@kYann
Copy link

kYann commented Aug 14, 2022

Maybe a way to fix this is to have a cast operator for the original connection type ?
There would be a add-on for each EFCoreProvider that would provide the CreateEntityConnection with the needed cast operator.

I'm really new to efcore plus as I've just downloaded it a few minutes ago.

@joaofx
Copy link

joaofx commented Dec 16, 2022

After updating my project to .NET 7, EF7, Npgsql 7, and EntityFramework-Plus' last version, I don't get this Exception anymore and it seems to be working correctly. Give a try!

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

No branches or pull requests

7 participants