mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update Insertable
This commit is contained in:
@@ -53,17 +53,36 @@ namespace SqlSugar
|
||||
RestoreMapping();
|
||||
return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
}
|
||||
public long ExecuteReturnBigIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
}
|
||||
public T ExecuteReturnEntity()
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys=GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) return result;
|
||||
var idValue = ExecuteReturnIdentity();
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { this.ExecuteCommand(); return result; }
|
||||
var idValue = ExecuteReturnBigIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteReutrnEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result,idValue,null);
|
||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result, idValue, null);
|
||||
return result;
|
||||
}
|
||||
public bool ExecuteCommandIdentityIntoEntity()
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { return this.ExecuteCommand() > 0; }
|
||||
var idValue = ExecuteReturnBigIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result, idValue, null);
|
||||
return idValue>0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Setting
|
||||
|
@@ -12,6 +12,8 @@ namespace SqlSugar
|
||||
int ExecuteCommand();
|
||||
int ExecuteReturnIdentity();
|
||||
T ExecuteReturnEntity();
|
||||
bool ExecuteCommandIdentityIntoEntity();
|
||||
long ExecuteReturnBigIdentity();
|
||||
IInsertable<T> AS(string tableName);
|
||||
IInsertable<T> With(string lockString);
|
||||
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);
|
||||
|
Reference in New Issue
Block a user