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

Error with TransactionScope when using FutureValue with Async #763

Closed
SpaceOgre opened this issue May 16, 2023 · 5 comments
Closed

Error with TransactionScope when using FutureValue with Async #763

SpaceOgre opened this issue May 16, 2023 · 5 comments
Assignees

Comments

@SpaceOgre
Copy link

SpaceOgre commented May 16, 2023

1. Description

When using FutureValue in a TransactionScope, but only in async, a Specified method is not supported. error is receive. It needs to be atleast two queries since it fails when running them as a batch, if I turn the batch mode off it works again.

This only happens when using the Async methods (ToListAsync or ValueAsync) when using the sync methods it works.

I can run multiple Future() operations like this but as soon as I add one FutureValue the error is received. It also appears when having multiple FutureValue and no Future.

The produced SQL runs as it should, so it is only a problem with parsing the result.

2. Exception

Exception message:
Specified method is not supported.

Stack trace:
   at System.Data.Common.DbConnection.EnlistTransaction(Transaction transaction)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.ConnectionEnlistTransaction(Transaction transaction)
   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.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.<>c.<MoveNext>b__21_0(DbContext _, Enumerator enumerator)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
   at Z.EntityFramework.Plus.QueryFutureEnumerable`1.SetResult(IEnumerator`1 enumerator)
   at Z.EntityFramework.Plus.QueryFutureEnumerable`1.SetResult(DbDataReader reader)
   at Z.EntityFramework.Plus.QueryFutureBatch.<ExecuteQueriesAsync>d__14.MoveNext()
   at Z.EntityFramework.Plus.QueryFutureValue`1.<ValueAsync>d__4.MoveNext()
   at GR.Elevinformation.Library.DataAccess.QueryableExtensions.PaginatedListQueryableExtensions.<ToPaginatedListAsync>d__2`1.MoveNext() in C:\Users\Nordstrom\source\GR\Elevinformation.API\source\GR.Elevinformation.Library\DataAccess\QueryableExtensions\PaginatedListQueryableExtensions.cs:line 30

3. Fiddle or Project

using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
var futureTotalCount = _dbContext.Users.DeferredCount().FutureValue();
var futureItems = _dbContext.Users.Future();
var items = await futureItems.ToListAsync(); //Throws here, if I change to ToList() it works

4. Any further technical details

  • Net 7
  • EF Core 7
  • Z.EntityFramework.Plus.EFCore 7.22.0
@JonathanMagnan JonathanMagnan self-assigned this May 17, 2023
@JonathanMagnan
Copy link
Member

Hello @SpaceOgre ,

Thank you for reporting.

We will see if there is something we can do here or not.

@JonathanMagnan
Copy link
Member

Hello @SpaceOgre ,

Just to let you know that we think we have found the issue.

The fix should be released next week if the code review is accepted.

Best Regards,

Jon

@SpaceOgre
Copy link
Author

@JonathanMagnan great news, thanks for the fast work!

@JonathanMagnan
Copy link
Member

Hello @SpaceOgre ,

The v7.22.2 is now available.

Could you try it and let us know if we correctly fixed the issue?

Best Regards,

Jon

@SpaceOgre
Copy link
Author

@JonathanMagnan have tested it and the issue is now solved. Thanks for your help!

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

2 participants