Browse Source

-

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

21
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);

Loading…
Cancel
Save