From a3f612c835a4a8189b15d5090aa554ad6d5b46cf Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 13 Nov 2022 19:06:59 +0800 Subject: [PATCH] Synchronization code --- .../InsertableProvider/InsertableProvider.cs | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index bb89e22e6..c20e2e308 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -113,14 +113,14 @@ namespace SqlSugar if (InsertBuilder.IsOleDb) { var isAuto = false; - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) + if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { - isAuto = true; + isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); - if (isAuto) + if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; @@ -145,14 +145,14 @@ namespace SqlSugar if (InsertBuilder.IsOleDb) { var isAuto = false; - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) + if (this.Context.Ado.IsAnyTran()==false&&this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { - isAuto = true; + isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); - if (isAuto) + if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; @@ -305,14 +305,14 @@ namespace SqlSugar if (InsertBuilder.IsOleDb) { var isAuto = false; - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) + if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { - isAuto = true; + isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); - if (isAuto) + if(this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; @@ -379,7 +379,24 @@ namespace SqlSugar return 0; } string sql = _ExecuteReturnBigIdentity(); - var result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + long result = 0; + if (InsertBuilder.IsOleDb) + { + var isAuto = false; + if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) + { + isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; + this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; + } + result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); + if (this.Context.Ado.IsAnyTran() == false && isAuto) + { + this.Ado.Close(); + this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; + } + } + result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); After(sql, result); return result; }