-
Notifications
You must be signed in to change notification settings - Fork 171
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
在上下文 中 封装事务 报错 #273
Comments
不太清楚这段代码的意义 _publisherTransactionFactory.BeginTransaction(this); |
直接使用 using(var tran=dbcontex.Database.beginTransaction()){
tran.commit();
} |
_publisherTransactionFactory.BeginTransaction(this); 这个是用外部事务。
开启事务
|
@xiantaibai 先尝试一下普通的事务开启是否可以 |
我使用原生 注入 ,是没问题的。改成 AddShardingDbContext 就会出现上面的问题
|
我说的是addShardingDbcontext加普通模式开启事务 using(var tran=dbcontex.Database.beginTransaction()){
tran.commit();
} |
addShardingDbcontext加普通模式开启事务 报同样的错误,执行到 iotDbContext.Add(message); 报错
|
这是启动配置
|
@xiantaibai |
执行 dbcontext.SaveEntitiesAsync();
错误类型
System.InvalidOperationException: The specified transaction is not associated with the current connection. Only transactions associated with the current connection may be used.
at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction..ctor(IRelationalConnection connection, DbTransaction transaction, Guid transactionId, IDiagnosticsLogger
1 logger, Boolean transactionOwned, ISqlGenerationHelper sqlGenerationHelper) at Microsoft.EntityFrameworkCore.Storage.RelationalTransactionFactory.Create(IRelationalConnection connection, DbTransaction transaction, Guid transactionId, IDiagnosticsLogger
1 logger, Boolean transactionOwned)at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.CreateRelationalTransaction(DbTransaction transaction, Guid transactionId, Boolean transactionOwned)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.UseTransaction(DbTransaction transaction, Guid transactionId)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.UseTransaction(DatabaseFacade databaseFacade, DbTransaction transaction, Guid transactionId)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.UseTransaction(DatabaseFacade databaseFacade, DbTransaction transaction)
at ShardingCore.Sharding.ShardingDbContextExecutors.DataSourceDbContext.JoinCurrentTransaction()
at ShardingCore.Sharding.ShardingDbContextExecutors.DataSourceDbContext.NotifyTransaction()
at ShardingCore.Sharding.ShardingDbContextExecutors.ShardingDbContextExecutor.NotifyShardingTransaction()
at ShardingCore.EFCores.ShardingRelationalTransactionManager.BeginTransaction(IsolationLevel isolationLevel)
at ShardingCore.EFCores.ShardingRelationalTransactionManager.BeginTransaction()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.BeginTransaction()
数据库上下文
The text was updated successfully, but these errors were encountered: