- 增加 Async CancellationToken IInsert/IUdate/IInsertOrUpdate;

This commit is contained in:
2881099
2020-11-12 06:35:29 +08:00
parent 2222fa269e
commit 8bbb7329f9
45 changed files with 492 additions and 433 deletions

View File

@ -6,6 +6,7 @@ using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FreeSql.MsAccess.Curd
@ -102,11 +103,11 @@ namespace FreeSql.MsAccess.Curd
#if net40
#else
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(1, 1000);
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(1, 1000);
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(1, 1000);
public override Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(1, 1000, cancellationToken);
public override Task<long> ExecuteIdentityAsync(CancellationToken cancellationToken = default) => base.SplitExecuteIdentityAsync(1, 1000, cancellationToken);
public override Task<List<T1>> ExecuteInsertedAsync(CancellationToken cancellationToken = default) => base.SplitExecuteInsertedAsync(1, 1000, cancellationToken);
async protected override Task<int> RawExecuteAffrowsAsync()
async protected override Task<int> RawExecuteAffrowsAsync(CancellationToken cancellationToken = default)
{
var sql = this.ToSql();
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
@ -115,7 +116,7 @@ namespace FreeSql.MsAccess.Curd
Exception exception = null;
try
{
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params);
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken);
}
catch (Exception ex)
{
@ -129,7 +130,7 @@ namespace FreeSql.MsAccess.Curd
}
return affrows;
}
async protected override Task<long> RawExecuteIdentityAsync()
async protected override Task<long> RawExecuteIdentityAsync(CancellationToken cancellationToken = default)
{
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return 0;
@ -146,14 +147,14 @@ namespace FreeSql.MsAccess.Curd
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_connection = conn.Value;
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params);
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _commandTimeout, _params)), out ret);
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken);
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _commandTimeout, _params, cancellationToken)), out ret);
}
}
else
{
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params);
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _commandTimeout, _params)), out ret);
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken);
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, "SELECT @@identity", _commandTimeout, _params, cancellationToken)), out ret);
}
}
catch (Exception ex)
@ -169,13 +170,13 @@ namespace FreeSql.MsAccess.Curd
}
return ret;
}
async protected override Task<List<T1>> RawExecuteInsertedAsync()
async protected override Task<List<T1>> RawExecuteInsertedAsync(CancellationToken cancellationToken = default)
{
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return new List<T1>();
var ret = _source.ToList();
await this.RawExecuteAffrowsAsync();
await this.RawExecuteAffrowsAsync(cancellationToken);
return ret;
}
#endif