Browse Source

-

pull/1/head
skx 4 years ago
parent
commit
93c76d9052
  1. 23
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs

23
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs

@ -75,7 +75,28 @@ namespace SqlSugar
public object ExecuteReturnPrimaryKey() 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) if (InsertObjects != null && InsertObjects.Count() > 0)
{ {
var isIdEntity = IsIdEntity(this.Entity); var isIdEntity = IsIdEntity(this.Entity);
@ -90,7 +111,7 @@ namespace SqlSugar
{ {
id = this.Context.Insertable(InsertObject).ExecuteReturnIdentity(); 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); AddChildList(this.SubList, InsertObject, pk);
} }
return InsertObjects.Count(); return InsertObjects.Count();

Loading…
Cancel
Save