mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Add Rep.InsertReturnEntity
This commit is contained in:
@@ -238,7 +238,20 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var result = InsertObjs.First();
|
var result = InsertObjs.First();
|
||||||
var identityKeys = GetIdentityKeys();
|
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();
|
var idValue = ExecuteReturnBigIdentity();
|
||||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||||
var identityKey = identityKeys.First();
|
var identityKey = identityKeys.First();
|
||||||
@@ -290,7 +303,20 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var result = InsertObjs.First();
|
var result = InsertObjs.First();
|
||||||
var identityKeys = GetIdentityKeys();
|
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();
|
var idValue =await ExecuteReturnBigIdentityAsync();
|
||||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||||
var identityKey = identityKeys.First();
|
var identityKey = identityKeys.First();
|
||||||
|
@@ -44,6 +44,7 @@ namespace SqlSugar
|
|||||||
long InsertReturnBigIdentity(T insertObj);
|
long InsertReturnBigIdentity(T insertObj);
|
||||||
long InsertReturnSnowflakeId(T insertObj);
|
long InsertReturnSnowflakeId(T insertObj);
|
||||||
List<long> InsertReturnSnowflakeId(List<T> insertObjs);
|
List<long> InsertReturnSnowflakeId(List<T> insertObjs);
|
||||||
|
T InsertReturnEntity(T insertObj);
|
||||||
|
|
||||||
|
|
||||||
bool IsAny(Expression<Func<T, bool>> whereExpression);
|
bool IsAny(Expression<Func<T, bool>> whereExpression);
|
||||||
@@ -79,6 +80,7 @@ namespace SqlSugar
|
|||||||
Task<long> InsertReturnBigIdentityAsync(T insertObj);
|
Task<long> InsertReturnBigIdentityAsync(T insertObj);
|
||||||
Task<long> InsertReturnSnowflakeIdAsync(T insertObj);
|
Task<long> InsertReturnSnowflakeIdAsync(T insertObj);
|
||||||
Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs);
|
Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs);
|
||||||
|
Task<T> InsertReturnEntityAsync(T insertObj);
|
||||||
|
|
||||||
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);
|
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);
|
||||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, 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();
|
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual T InsertReturnEntity(T insertObj)
|
||||||
|
{
|
||||||
|
return this.Context.Insertable(insertObj).ExecuteReturnEntity();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool InsertRange(T[] insertObjs)
|
public virtual bool InsertRange(T[] insertObjs)
|
||||||
{
|
{
|
||||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||||
@@ -308,6 +314,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync();
|
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)
|
public virtual async Task<bool> InsertRangeAsync(T[] insertObjs)
|
||||||
{
|
{
|
||||||
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
||||||
|
Reference in New Issue
Block a user