- 优化 UnitOfWork 与 ForUpdate 事务开启逻辑;

This commit is contained in:
2881099
2022-12-08 15:49:18 +08:00
parent 09864eaa9f
commit 80cfa45f51
4 changed files with 17 additions and 4 deletions

View File

@ -47,6 +47,7 @@ namespace FreeSql.Internal.CommonProvider
public Func<bool> _cancel;
public bool _is_AsTreeCte;
public BaseDiyMemberExpression _diymemexpWithTempQuery;
public Func<DbTransaction> _resolveHookTransaction;
public bool IsDefaultSqlContent => _distinct == false && _is_AsTreeCte == false && _tables.Count == 1 && _where.Length == 0 && _join.Length == 0 &&
string.IsNullOrWhiteSpace(_orderby) && string.IsNullOrWhiteSpace(_groupby) && string.IsNullOrWhiteSpace(_tosqlAppendContent) &&
@ -1187,8 +1188,9 @@ namespace FreeSql.Internal.CommonProvider
}
public TSelect ForUpdate(bool noawait = false)
{
if (_transaction == null && _orm.Ado.TransactionCurrentThread == null)
throw new Exception($"{CoreStrings.Begin_Transaction_Then_ForUpdate}");
if (_transaction == null && _orm.Ado.TransactionCurrentThread != null) this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction == null && _resolveHookTransaction != null) this.WithTransaction(_resolveHookTransaction());
if (_transaction == null) throw new Exception($"{CoreStrings.Begin_Transaction_Then_ForUpdate}");
switch (_orm.Ado.DataType)
{
case DataType.MySql: