Synchronization code

This commit is contained in:
sunkaixuan 2023-12-14 17:17:16 +08:00
parent aee9dd5102
commit d5d44b4475
2 changed files with 34 additions and 0 deletions

View File

@ -151,6 +151,38 @@ namespace SqlSugar
result += updateRow;
return result;
}
public T ExecuteReturnEntity()
{
var x = this.ToStorage();
if (x.InsertList?.Any()==true)
{
var data = x.AsInsertable.ExecuteReturnEntity();
x.AsUpdateable.ExecuteCommand();
return data;
}
else
{
x.AsInsertable.ExecuteCommand();
x.AsUpdateable.ExecuteCommand();
return x.UpdateList.FirstOrDefault()?.Item;
}
}
public async Task<T> ExecuteReturnEntityAsync()
{
var x = this.ToStorage();
if (x.InsertList.Any())
{
var data = await x.AsInsertable.ExecuteReturnEntityAsync();
await x.AsUpdateable.ExecuteCommandAsync();
return data;
}
else
{
await x.AsInsertable.ExecuteCommandAsync();
await x.AsUpdateable.ExecuteCommandAsync();
return x.UpdateList.FirstOrDefault()?.Item;
}
}
public Task<int> ExecuteCommandAsync(CancellationToken cancellationToken)
{
this.Context.Ado.CancellationToken=cancellationToken;

View File

@ -29,6 +29,8 @@ namespace SqlSugar
Task<StorageableResult<T>> ToStorageAsync();
IStorageable<T> As(string tableName);
int ExecuteCommand();
T ExecuteReturnEntity();
Task<T> ExecuteReturnEntityAsync();
Task<int> ExecuteCommandAsync();
Task<int> ExecuteCommandAsync(CancellationToken cancellationToken);
int ExecuteSqlBulkCopy();