Synchronization code

This commit is contained in:
sunkaixuan 2023-09-25 16:10:34 +08:00
parent 6d0fe85cd0
commit 14e132c5fb
7 changed files with 28 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
@ -150,6 +151,11 @@ namespace SqlSugar
result += updateRow; result += updateRow;
return result; return result;
} }
public Task<int> ExecuteCommandAsync(CancellationToken cancellationToken)
{
this.Context.Ado.CancellationToken=cancellationToken;
return ExecuteCommandAsync();
}
public async Task<int> ExecuteCommandAsync() public async Task<int> ExecuteCommandAsync()
{ {
var result = 0; var result = 0;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
@ -56,8 +57,10 @@ namespace SqlSugar
} }
return result; return result;
} }
public async Task<int> ExecuteCommandAsync() public async Task<int> ExecuteCommandAsync(CancellationToken? cancellationToken=null)
{ {
if (cancellationToken != null)
this.Context.Ado.CancellationToken = cancellationToken.Value;
if (Data.Count() == 1 && Data.First() == null) if (Data.Count() == 1 && Data.First() == null)
{ {
return 0; return 0;
@ -121,8 +124,10 @@ namespace SqlSugar
} }
return result; return result;
} }
public async Task<int> ExecuteSqlBulkCopyAsync() public async Task<int> ExecuteSqlBulkCopyAsync(CancellationToken? cancellationToken = null)
{ {
if(cancellationToken!=null)
this.Context.Ado.CancellationToken = cancellationToken.Value;
if (Data.Count() == 1 && Data.First() == null) if (Data.Count() == 1 && Data.First() == null)
{ {
return 0; return 0;

View File

@ -1006,6 +1006,10 @@ namespace SqlSugar
#endregion #endregion
#region Saveable #region Saveable
public IStorageable<T> Storageable<T>(T[] dataList) where T : class, new()
{
return Storageable(dataList?.ToList());
}
public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new() public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
{ {
return new SaveableProvider<T>(this, saveObjects); return new SaveableProvider<T>(this, saveObjects);

View File

@ -602,6 +602,10 @@ namespace SqlSugar
{ {
return ScopedContext.SqlQueryable<T>(sql); return ScopedContext.SqlQueryable<T>(sql);
} }
public IStorageable<T> Storageable<T>(T[] dataList) where T : class, new()
{
return ScopedContext.Storageable(dataList);
}
public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName) public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName)
{ {
return ScopedContext.Storageable(dictionaryList, tableName); return ScopedContext.Storageable(dictionaryList, tableName);

View File

@ -146,6 +146,7 @@ namespace SqlSugar
#endregion #endregion
#region Saveable #region Saveable
IStorageable<T> Storageable<T>(T[] dataList) where T : class, new();
StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName); StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName);
StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName); StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName);
IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new(); IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new();

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
{ {
@ -29,6 +30,7 @@ namespace SqlSugar
IStorageable<T> As(string tableName); IStorageable<T> As(string tableName);
int ExecuteCommand(); int ExecuteCommand();
Task<int> ExecuteCommandAsync(); Task<int> ExecuteCommandAsync();
Task<int> ExecuteCommandAsync(CancellationToken cancellationToken);
int ExecuteSqlBulkCopy(); int ExecuteSqlBulkCopy();
Task<int> ExecuteSqlBulkCopyAsync(); Task<int> ExecuteSqlBulkCopyAsync();
IStorageable<T> DefaultAddElseUpdate(); IStorageable<T> DefaultAddElseUpdate();

View File

@ -556,6 +556,10 @@ namespace SqlSugar
{ {
return this.Context.Storageable(dataList); return this.Context.Storageable(dataList);
} }
public IStorageable<T> Storageable<T>(T[] dataList) where T : class, new()
{
return this.Context.Storageable(dataList?.ToList());
}
public IStorageable<T> Storageable<T>(T data) where T : class, new() public IStorageable<T> Storageable<T>(T data) where T : class, new()
{ {
Check.Exception(typeof(T).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() "); Check.Exception(typeof(T).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ");