mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
-
This commit is contained in:
parent
8abb8d537a
commit
93c76d9052
@ -75,7 +75,28 @@ namespace SqlSugar
|
||||
|
||||
public object ExecuteReturnPrimaryKey()
|
||||
{
|
||||
var isNoTrean = this.Context.Ado.Transaction == null;
|
||||
try
|
||||
{
|
||||
if (isNoTrean)
|
||||
this.Context.Ado.BeginTran();
|
||||
|
||||
var result = Execute();
|
||||
|
||||
if (isNoTrean)
|
||||
this.Context.Ado.CommitTran();
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (isNoTrean)
|
||||
this.Context.Ado.RollbackTran();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private object Execute()
|
||||
{
|
||||
if (InsertObjects != null && InsertObjects.Count() > 0)
|
||||
{
|
||||
var isIdEntity = IsIdEntity(this.Entity);
|
||||
@ -90,7 +111,7 @@ namespace SqlSugar
|
||||
{
|
||||
id = this.Context.Insertable(InsertObject).ExecuteReturnIdentity();
|
||||
}
|
||||
var pk = GetPrimaryKey(this.Entity,InsertObject, id);
|
||||
var pk = GetPrimaryKey(this.Entity, InsertObject, id);
|
||||
AddChildList(this.SubList, InsertObject, pk);
|
||||
}
|
||||
return InsertObjects.Count();
|
||||
|
Loading…
Reference in New Issue
Block a user