mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Add Rep.InsertReturnEntity
This commit is contained in:
parent
d863b3d7b5
commit
8f488902a1
@ -238,7 +238,20 @@ namespace SqlSugar
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { return this.ExecuteCommand() > 0; }
|
||||
if (identityKeys.Count == 0)
|
||||
{
|
||||
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey = true && it.UnderType == UtilConstants.LongType);
|
||||
if (snowColumn!=null)
|
||||
{
|
||||
var id = this.ExecuteReturnSnowflakeId();
|
||||
snowColumn.PropertyInfo.SetValue(result, id);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.ExecuteCommand() > 0;
|
||||
}
|
||||
}
|
||||
var idValue = ExecuteReturnBigIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
@ -290,7 +303,20 @@ namespace SqlSugar
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { return await this.ExecuteCommandAsync() > 0; }
|
||||
if (identityKeys.Count == 0)
|
||||
{
|
||||
var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey = true && it.UnderType == UtilConstants.LongType);
|
||||
if (snowColumn != null)
|
||||
{
|
||||
var id =await this.ExecuteReturnSnowflakeIdAsync();
|
||||
snowColumn.PropertyInfo.SetValue(result, id);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return await this.ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
var idValue =await ExecuteReturnBigIdentityAsync();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
|
@ -44,6 +44,7 @@ namespace SqlSugar
|
||||
long InsertReturnBigIdentity(T insertObj);
|
||||
long InsertReturnSnowflakeId(T insertObj);
|
||||
List<long> InsertReturnSnowflakeId(List<T> insertObjs);
|
||||
T InsertReturnEntity(T insertObj);
|
||||
|
||||
|
||||
bool IsAny(Expression<Func<T, bool>> whereExpression);
|
||||
@ -79,6 +80,7 @@ namespace SqlSugar
|
||||
Task<long> InsertReturnBigIdentityAsync(T insertObj);
|
||||
Task<long> InsertReturnSnowflakeIdAsync(T insertObj);
|
||||
Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs);
|
||||
Task<T> InsertReturnEntityAsync(T insertObj);
|
||||
|
||||
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
|
@ -182,6 +182,12 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||
}
|
||||
|
||||
public virtual T InsertReturnEntity(T insertObj)
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
public virtual bool InsertRange(T[] insertObjs)
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
@ -308,6 +314,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync();
|
||||
}
|
||||
public virtual async Task<T> InsertReturnEntityAsync(T insertObj)
|
||||
{
|
||||
return await this.Context.Insertable(insertObj).ExecuteReturnEntityAsync();
|
||||
}
|
||||
public virtual async Task<bool> InsertRangeAsync(T[] insertObjs)
|
||||
{
|
||||
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
||||
|
Loading…
Reference in New Issue
Block a user