mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 IUpdate.ExecuteUpdated 指定字段返回;#1681
This commit is contained in:
parent
8692efcd3d
commit
1f0fccf977
@ -1104,82 +1104,6 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder">
|
||||
<summary>
|
||||
动态创建实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.#ctor(IFreeSql,System.String,System.Attribute[])">
|
||||
<summary>
|
||||
配置Class
|
||||
</summary>
|
||||
<param name="className">类名</param>
|
||||
<param name="attributes">类标记的特性[Table(Name = "xxx")] [Index(xxxx)]</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="isOverride">该属性是否重写父类属性</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Object,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="isOverride">该属性是否重写父类属性</param>
|
||||
<param name="defaultValue">属性默认值</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Extend(System.Type)">
|
||||
<summary>
|
||||
配置父类
|
||||
</summary>
|
||||
<param name="superClass">父类类型</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.OverrideProperty(System.Reflection.Emit.TypeBuilder@,System.Reflection.Emit.MethodBuilder,FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.PropertyMethodEnum,System.String)">
|
||||
<summary>
|
||||
Override属性
|
||||
</summary>
|
||||
<param name="typeBuilder"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Build">
|
||||
<summary>
|
||||
Emit动态创建出Class - Type
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToLower(System.String)">
|
||||
<summary>
|
||||
首字母小写
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToUpper(System.String)">
|
||||
<summary>
|
||||
首字母大写
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
||||
<summary>
|
||||
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
||||
@ -3346,6 +3270,13 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IUpdate`1.ExecuteUpdatedAsync(System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
执行SQL语句,返回更新后的记录<para></para>
|
||||
注意:此方法只有 Postgresql/SqlServer 有效果
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IUpdateJoin`2.WithTransaction(System.Data.Common.DbTransaction)">
|
||||
<summary>
|
||||
指定事务对象
|
||||
@ -5877,28 +5808,6 @@
|
||||
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.DynamicEntity(FreeSql.ICodeFirst,System.String,System.Attribute[])">
|
||||
<summary>
|
||||
动态构建Class Type
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateInstance(FreeSql.Internal.Model.TableInfo,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||
<summary>
|
||||
根据字典,创建 table 对应的实体对象
|
||||
</summary>
|
||||
<param name="table"></param>
|
||||
<param name="dict"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateDictionary(FreeSql.Internal.Model.TableInfo,System.Object)">
|
||||
<summary>
|
||||
根据实体对象,创建 table 对应的字典
|
||||
</summary>
|
||||
<param name="table"></param>
|
||||
<param name="instance"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExpressionCallExtensions.Between(System.DateTime,System.DateTime,System.DateTime)">
|
||||
<summary>
|
||||
C#: that >= between && that <= and<para></para>
|
||||
|
@ -286,11 +286,18 @@ namespace FreeSql
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<T1> ExecuteUpdated();
|
||||
List<TReturn> ExecuteUpdated<TReturn>(Expression<Func<T1, TReturn>> returnColumns);
|
||||
|
||||
#if net40
|
||||
#else
|
||||
Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||
Task<List<T1>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
||||
Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||
/// <summary>
|
||||
/// 执行SQL语句,返回更新后的记录<para></para>
|
||||
/// 注意:此方法只有 Postgresql/SqlServer 有效果
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<T1>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
||||
Task<List<TReturn>> ExecuteUpdatedAsync<TReturn>(Expression<Func<T1, TReturn>> returnColumns, CancellationToken cancellationToken = default);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@ -350,156 +350,105 @@ namespace FreeSql.Internal.CommonProvider
|
||||
ret[a] = _source.GetRange(a * takeMax, Math.Min(takeMax, _source.Count - a * takeMax));
|
||||
return ret;
|
||||
}
|
||||
protected virtual int SplitExecuteAffrows(int valuesLimit, int parameterLimit)
|
||||
void SplitExecute(int valuesLimit, int parameterLimit, string traceName, Action execute)
|
||||
{
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
var ret = 0;
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
ret = this.RawExecuteAffrows();
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
execute();
|
||||
ClearData();
|
||||
return;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
|
||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrows", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret += this.RawExecuteAffrows();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret += this.RawExecuteAffrows();
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
var before = new Aop.TraceBeforeEventArgs(traceName, null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
execute();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
execute();
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
}
|
||||
|
||||
protected virtual int SplitExecuteAffrows(int valuesLimit, int parameterLimit)
|
||||
{
|
||||
var ret = 0;
|
||||
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteAffrows", () =>
|
||||
ret += this.RawExecuteAffrows()
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected virtual List<T1> SplitExecuteUpdated(int valuesLimit, int parameterLimit)
|
||||
{
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
var ret = new List<T1>();
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
ret = this.RawExecuteUpdated();
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteUpdated", () =>
|
||||
ret.AddRange(this.RawExecuteUpdated())
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
protected virtual List<TReturn> SplitExecuteUpdated<TReturn>(int valuesLimit, int parameterLimit, Expression<Func<T1, TReturn>> returnColumns)
|
||||
{
|
||||
var ret = new List<TReturn>();
|
||||
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteUpdated", () =>
|
||||
ret.AddRange(this.RawExecuteUpdated(returnColumns))
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
|
||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdated", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret.AddRange(this.RawExecuteUpdated());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret.AddRange(this.RawExecuteUpdated());
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected int RawExecuteAffrows()
|
||||
protected int RawExecuteAffrows()
|
||||
{
|
||||
var affrows = 0;
|
||||
DbParameter[] dbParms = null;
|
||||
@ -532,11 +481,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
|
||||
protected abstract List<T1> RawExecuteUpdated();
|
||||
protected abstract List<TReturn> RawExecuteUpdated<TReturn>(Expression<Func<T1, TReturn>> returnColumns);
|
||||
|
||||
public abstract int ExecuteAffrows();
|
||||
public abstract int ExecuteAffrows();
|
||||
public abstract List<T1> ExecuteUpdated();
|
||||
public abstract List<TReturn> ExecuteUpdated<TReturn>(Expression<Func<T1, TReturn>> returnColumns);
|
||||
|
||||
public IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns) => IgnoreColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||
public IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns) => IgnoreColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||
public IUpdate<T1> UpdateColumns(Expression<Func<T1, object>> columns) => UpdateColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||
|
||||
public IUpdate<T1> IgnoreColumns(string[] columns)
|
||||
|
@ -18,154 +18,104 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
#if net40
|
||||
#else
|
||||
async protected virtual Task<int> SplitExecuteAffrowsAsync(int valuesLimit, int parameterLimit, CancellationToken cancellationToken = default)
|
||||
async protected virtual Task SplitExecuteAsync(int valuesLimit, int parameterLimit, string traceName, Func<Task> executeAsync, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
var ret = 0;
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
ret = await this.RawExecuteAffrowsAsync(cancellationToken);
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
await executeAsync();
|
||||
ClearData();
|
||||
return;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
|
||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrowsAsync", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
var before = new Aop.TraceBeforeEventArgs(traceName, null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
await executeAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
await executeAsync();
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
}
|
||||
|
||||
async protected virtual Task<int> SplitExecuteAffrowsAsync(int valuesLimit, int parameterLimit, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ret = 0;
|
||||
await SplitExecuteAsync(valuesLimit, parameterLimit, "SplitExecuteAffrowsAsync", async () =>
|
||||
ret += await this.RawExecuteAffrowsAsync(cancellationToken)
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
async protected virtual Task<List<T1>> SplitExecuteUpdatedAsync(int valuesLimit, int parameterLimit, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
||||
var ret = new List<T1>();
|
||||
if (ss.Length <= 1)
|
||||
{
|
||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||
ret = await this.RawExecuteUpdatedAsync(cancellationToken);
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
if (_transaction == null)
|
||||
{
|
||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||
}
|
||||
var ret = new List<T1>();
|
||||
await SplitExecuteAsync(valuesLimit, parameterLimit, "SplitExecuteUpdatedAsync", async () =>
|
||||
ret.AddRange(await this.RawExecuteUpdatedAsync(cancellationToken))
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
async protected virtual Task<List<TReturn>> SplitExecuteUpdatedAsync<TReturn>(int valuesLimit, int parameterLimit, Expression<Func<T1, TReturn>> returnColumns, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ret = new List<TReturn>();
|
||||
await SplitExecuteAsync(valuesLimit, parameterLimit, "SplitExecuteUpdatedAsync", async () =>
|
||||
ret.AddRange(await this.RawExecuteUpdatedAsync(returnColumns, cancellationToken))
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdatedAsync", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (_transaction != null || _batchAutoTransaction == false)
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret.AddRange(await this.RawExecuteUpdatedAsync(cancellationToken));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
||||
{
|
||||
_transaction = conn.Value.BeginTransaction();
|
||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||
try
|
||||
{
|
||||
for (var a = 0; a < ss.Length; a++)
|
||||
{
|
||||
_source = ss[a];
|
||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||
ret.AddRange(await this.RawExecuteUpdatedAsync(cancellationToken));
|
||||
}
|
||||
_transaction.Commit();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_transaction.Rollback();
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||
throw;
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
ClearData();
|
||||
return ret;
|
||||
}
|
||||
|
||||
async protected Task<int> RawExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
||||
async protected Task<int> RawExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var affrows = 0;
|
||||
DbParameter[] dbParms = null;
|
||||
@ -197,9 +147,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return affrows;
|
||||
}
|
||||
protected abstract Task<List<T1>> RawExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
||||
protected abstract Task<List<TReturn>> RawExecuteUpdatedAsync<TReturn>(Expression<Func<T1, TReturn>> returnColumns, CancellationToken cancellationToken = default);
|
||||
|
||||
public abstract Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||
public abstract Task<List<T1>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
||||
public abstract Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||
public abstract Task<List<T1>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
||||
public abstract Task<List<TReturn>> ExecuteUpdatedAsync<TReturn>(Expression<Func<T1, TReturn>> returnColumns, CancellationToken cancellationToken = default);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user