mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Update Insertable
This commit is contained in:
@@ -37,7 +37,7 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
|
|
||||||
//Insert reutrn Command Count
|
//Insert reutrn Command Count
|
||||||
var t2 = db.Insertable(insertObj).ExecuteCommand();
|
var t2 = db.Insertable(insertObj).ExecuteReturnEntity();
|
||||||
|
|
||||||
db.IgnoreColumns = null;
|
db.IgnoreColumns = null;
|
||||||
//Only insert Name
|
//Only insert Name
|
||||||
|
@@ -63,14 +63,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public T ExecuteReturnEntity()
|
public T ExecuteReturnEntity()
|
||||||
{
|
{
|
||||||
var result = InsertObjs.First();
|
ExecuteCommandIdentityIntoEntity();
|
||||||
var identityKeys = GetIdentityKeys();
|
return InsertObjs.First();
|
||||||
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);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
public bool ExecuteCommandIdentityIntoEntity()
|
public bool ExecuteCommandIdentityIntoEntity()
|
||||||
{
|
{
|
||||||
@@ -80,7 +74,12 @@ namespace SqlSugar
|
|||||||
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();
|
||||||
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result, idValue, null);
|
object setValue= 0;
|
||||||
|
if (idValue > int.MaxValue)
|
||||||
|
setValue = idValue;
|
||||||
|
else
|
||||||
|
setValue = Convert.ToInt32(idValue);
|
||||||
|
this.Context.EntityProvider.GetProperty<T>(identityKey).SetValue(result,setValue, null);
|
||||||
return idValue>0;
|
return idValue>0;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
Reference in New Issue
Block a user