mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 IUpdate.ExecuteUpdated 指定字段返回;#1681
This commit is contained in:
parent
8692efcd3d
commit
1f0fccf977
@ -1104,82 +1104,6 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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)">
|
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
||||||
@ -3346,6 +3270,13 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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)">
|
<member name="M:FreeSql.IUpdateJoin`2.WithTransaction(System.Data.Common.DbTransaction)">
|
||||||
<summary>
|
<summary>
|
||||||
指定事务对象
|
指定事务对象
|
||||||
@ -5877,28 +5808,6 @@
|
|||||||
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</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)">
|
<member name="M:FreeSqlGlobalExpressionCallExtensions.Between(System.DateTime,System.DateTime,System.DateTime)">
|
||||||
<summary>
|
<summary>
|
||||||
C#: that >= between && that <= and<para></para>
|
C#: that >= between && that <= and<para></para>
|
||||||
|
@ -286,11 +286,18 @@ namespace FreeSql
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
List<T1> ExecuteUpdated();
|
List<T1> ExecuteUpdated();
|
||||||
|
List<TReturn> ExecuteUpdated<TReturn>(Expression<Func<T1, TReturn>> returnColumns);
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||||
Task<List<T1>> ExecuteUpdatedAsync(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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -350,156 +350,105 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
ret[a] = _source.GetRange(a * takeMax, Math.Min(takeMax, _source.Count - a * takeMax));
|
ret[a] = _source.GetRange(a * takeMax, Math.Min(takeMax, _source.Count - a * takeMax));
|
||||||
return ret;
|
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 ss = SplitSource(valuesLimit, parameterLimit);
|
||||||
var ret = 0;
|
if (ss.Length <= 1)
|
||||||
if (ss.Length <= 1)
|
{
|
||||||
{
|
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
execute();
|
||||||
ret = this.RawExecuteAffrows();
|
ClearData();
|
||||||
ClearData();
|
return;
|
||||||
return ret;
|
}
|
||||||
}
|
if (_transaction == null)
|
||||||
if (_transaction == null)
|
{
|
||||||
{
|
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrows", null);
|
var before = new Aop.TraceBeforeEventArgs(traceName, null);
|
||||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||||
Exception exception = null;
|
Exception exception = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_transaction != null || _batchAutoTransaction == false)
|
if (_transaction != null || _batchAutoTransaction == false)
|
||||||
{
|
{
|
||||||
for (var a = 0; a < ss.Length; a++)
|
for (var a = 0; a < ss.Length; a++)
|
||||||
{
|
{
|
||||||
_source = ss[a];
|
_source = ss[a];
|
||||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||||
ret += this.RawExecuteAffrows();
|
execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||||
using (var conn = _orm.Ado.MasterPool.Get())
|
using (var conn = _orm.Ado.MasterPool.Get())
|
||||||
{
|
{
|
||||||
_transaction = conn.Value.BeginTransaction();
|
_transaction = conn.Value.BeginTransaction();
|
||||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (var a = 0; a < ss.Length; a++)
|
for (var a = 0; a < ss.Length; a++)
|
||||||
{
|
{
|
||||||
_source = ss[a];
|
_source = ss[a];
|
||||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||||
ret += this.RawExecuteAffrows();
|
execute();
|
||||||
}
|
}
|
||||||
_transaction.Commit();
|
_transaction.Commit();
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_transaction.Rollback();
|
_transaction.Rollback();
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
_transaction = null;
|
_transaction = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
exception = ex;
|
exception = ex;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||||
}
|
}
|
||||||
ClearData();
|
ClearData();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual int SplitExecuteAffrows(int valuesLimit, int parameterLimit)
|
||||||
|
{
|
||||||
|
var ret = 0;
|
||||||
|
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteAffrows", () =>
|
||||||
|
ret += this.RawExecuteAffrows()
|
||||||
|
);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual List<T1> SplitExecuteUpdated(int valuesLimit, int parameterLimit)
|
protected virtual List<T1> SplitExecuteUpdated(int valuesLimit, int parameterLimit)
|
||||||
{
|
{
|
||||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
if (ss.Length <= 1)
|
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteUpdated", () =>
|
||||||
{
|
ret.AddRange(this.RawExecuteUpdated())
|
||||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
);
|
||||||
ret = this.RawExecuteUpdated();
|
return ret;
|
||||||
ClearData();
|
}
|
||||||
return ret;
|
protected virtual List<TReturn> SplitExecuteUpdated<TReturn>(int valuesLimit, int parameterLimit, Expression<Func<T1, TReturn>> returnColumns)
|
||||||
}
|
{
|
||||||
if (_transaction == null)
|
var ret = new List<TReturn>();
|
||||||
{
|
SplitExecute(valuesLimit, parameterLimit, "SplitExecuteUpdated", () =>
|
||||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
ret.AddRange(this.RawExecuteUpdated(returnColumns))
|
||||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdated", null);
|
protected int RawExecuteAffrows()
|
||||||
_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()
|
|
||||||
{
|
{
|
||||||
var affrows = 0;
|
var affrows = 0;
|
||||||
DbParameter[] dbParms = null;
|
DbParameter[] dbParms = null;
|
||||||
@ -532,11 +481,13 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<T1> RawExecuteUpdated();
|
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<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> UpdateColumns(Expression<Func<T1, object>> columns) => UpdateColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||||
|
|
||||||
public IUpdate<T1> IgnoreColumns(string[] columns)
|
public IUpdate<T1> IgnoreColumns(string[] columns)
|
||||||
|
@ -18,154 +18,104 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#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 ss = SplitSource(valuesLimit, parameterLimit);
|
||||||
var ret = 0;
|
if (ss.Length <= 1)
|
||||||
if (ss.Length <= 1)
|
{
|
||||||
{
|
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
||||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
await executeAsync();
|
||||||
ret = await this.RawExecuteAffrowsAsync(cancellationToken);
|
ClearData();
|
||||||
ClearData();
|
return;
|
||||||
return ret;
|
}
|
||||||
}
|
if (_transaction == null)
|
||||||
if (_transaction == null)
|
{
|
||||||
{
|
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
||||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
||||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteAffrowsAsync", null);
|
var before = new Aop.TraceBeforeEventArgs(traceName, null);
|
||||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
_orm.Aop.TraceBeforeHandler?.Invoke(this, before);
|
||||||
Exception exception = null;
|
Exception exception = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_transaction != null || _batchAutoTransaction == false)
|
if (_transaction != null || _batchAutoTransaction == false)
|
||||||
{
|
{
|
||||||
for (var a = 0; a < ss.Length; a++)
|
for (var a = 0; a < ss.Length; a++)
|
||||||
{
|
{
|
||||||
_source = ss[a];
|
_source = ss[a];
|
||||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||||
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
|
await executeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
|
||||||
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
using (var conn = await _orm.Ado.MasterPool.GetAsync())
|
||||||
{
|
{
|
||||||
_transaction = conn.Value.BeginTransaction();
|
_transaction = conn.Value.BeginTransaction();
|
||||||
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
var transBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", null);
|
||||||
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (var a = 0; a < ss.Length; a++)
|
for (var a = 0; a < ss.Length; a++)
|
||||||
{
|
{
|
||||||
_source = ss[a];
|
_source = ss[a];
|
||||||
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
_batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, a + 1, ss.Length));
|
||||||
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
|
await executeAsync();
|
||||||
}
|
}
|
||||||
_transaction.Commit();
|
_transaction.Commit();
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_transaction.Rollback();
|
_transaction.Rollback();
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
_transaction = null;
|
_transaction = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
exception = ex;
|
exception = ex;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
var after = new Aop.TraceAfterEventArgs(before, null, exception);
|
||||||
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
_orm.Aop.TraceAfterHandler?.Invoke(this, after);
|
||||||
}
|
}
|
||||||
ClearData();
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
async protected virtual Task<List<T1>> SplitExecuteUpdatedAsync(int valuesLimit, int parameterLimit, CancellationToken cancellationToken = default)
|
async protected virtual Task<List<T1>> SplitExecuteUpdatedAsync(int valuesLimit, int parameterLimit, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var ss = SplitSource(valuesLimit, parameterLimit);
|
var ret = new List<T1>();
|
||||||
var ret = new List<T1>();
|
await SplitExecuteAsync(valuesLimit, parameterLimit, "SplitExecuteUpdatedAsync", async () =>
|
||||||
if (ss.Length <= 1)
|
ret.AddRange(await this.RawExecuteUpdatedAsync(cancellationToken))
|
||||||
{
|
);
|
||||||
if (_source?.Any() == true) _batchProgress?.Invoke(new BatchProgressStatus<T1>(_source, 1, 1));
|
return ret;
|
||||||
ret = await this.RawExecuteUpdatedAsync(cancellationToken);
|
}
|
||||||
ClearData();
|
async protected virtual Task<List<TReturn>> SplitExecuteUpdatedAsync<TReturn>(int valuesLimit, int parameterLimit, Expression<Func<T1, TReturn>> returnColumns, CancellationToken cancellationToken = default)
|
||||||
return ret;
|
{
|
||||||
}
|
var ret = new List<TReturn>();
|
||||||
if (_transaction == null)
|
await SplitExecuteAsync(valuesLimit, parameterLimit, "SplitExecuteUpdatedAsync", async () =>
|
||||||
{
|
ret.AddRange(await this.RawExecuteUpdatedAsync(returnColumns, cancellationToken))
|
||||||
var threadTransaction = _orm.Ado.TransactionCurrentThread;
|
);
|
||||||
if (threadTransaction != null) this.WithTransaction(threadTransaction);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
var before = new Aop.TraceBeforeEventArgs("SplitExecuteUpdatedAsync", null);
|
async protected Task<int> RawExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
||||||
_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)
|
|
||||||
{
|
{
|
||||||
var affrows = 0;
|
var affrows = 0;
|
||||||
DbParameter[] dbParms = null;
|
DbParameter[] dbParms = null;
|
||||||
@ -197,9 +147,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
protected abstract Task<List<T1>> RawExecuteUpdatedAsync(CancellationToken cancellationToken = default);
|
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<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
|
||||||
public abstract Task<List<T1>> ExecuteUpdatedAsync(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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user