- 修复 Ado.Net Crud 扩展方法事务的友好异常提示;

This commit is contained in:
28810
2020-09-05 18:45:36 +08:00
parent 44cff19ed4
commit 59ecfdf288
12 changed files with 145 additions and 15 deletions

View File

@ -202,9 +202,12 @@ namespace FreeSql.Internal.CommonProvider
try
{
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
if (_transaction != null)
if (_transaction != null || _orm.Ado.MasterPool == null)
{
_source = ss.Item1;
_SplitSourceByIdentityValueIsNullFlag = 1;
@ -305,9 +308,12 @@ namespace FreeSql.Internal.CommonProvider
try
{
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
if (_transaction != null)
if (_transaction != null || _orm.Ado.MasterPool == null)
{
_source = ss.Item1;
_SplitSourceByIdentityValueIsNullFlag = 1;

View File

@ -219,7 +219,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrows", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -237,6 +240,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@ -294,7 +298,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteIdentity", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -313,6 +320,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@ -371,7 +379,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteInserted", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -389,6 +400,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();

View File

@ -33,7 +33,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrowsAsync", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -51,6 +54,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@ -108,7 +112,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteIdentityAsync", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -127,6 +134,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@ -185,7 +193,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteInsertedAsync", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -203,6 +214,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();

View File

@ -158,7 +158,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrows", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -176,6 +179,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@ -228,7 +232,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdated", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -246,6 +253,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();

View File

@ -29,7 +29,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrowsAsync", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -47,6 +50,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@ -98,7 +102,10 @@ namespace FreeSql.Internal.CommonProvider
return ret;
}
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
{
var threadTransaction = _orm.Ado.TransactionCurrentThread;
if (threadTransaction != null) this.WithTransaction(threadTransaction);
}
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdatedAsync", null);
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
@ -116,6 +123,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();