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