Add: Storageable.ExecuteReturnEntity

This commit is contained in:
sunkaixuan
2023-12-14 16:48:34 +08:00
parent 15fd47e9c9
commit aee9dd5102
3 changed files with 35 additions and 1 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();

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>SqlSugarCore</id>
<version>5.1.4.127-preview13</version>
<version>5.1.4.127-preview29</version>
<authors>sunkaixuan</authors>
<owners>果糖大数据科技</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>