Update Insertable

This commit is contained in:
sunkaixuan
2017-09-01 12:54:02 +08:00
parent 3c6a771900
commit a05c43cfb0
2 changed files with 9 additions and 10 deletions

View File

@@ -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

View File

@@ -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