diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index 851a03ab6..0990c9550 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs @@ -257,6 +257,7 @@ namespace SqlSugar #region Methods public override bool UpdateColumn(string tableName, DbColumnInfo column) { + var isTran = this.Context.Ado.IsNoTran(); try { if (column.IsPrimarykey) @@ -264,8 +265,9 @@ namespace SqlSugar Check.ExceptionEasy("Sqlite no support alter column primary key","Sqlite不支持修改主键"); } - // Start a transaction - this.Context.Ado.BeginTran(); + if (isTran) + // Start a transaction + this.Context.Ado.BeginTran(); tableName = tableName ?? column.TableName; var oldColumn = column.DbColumnName; @@ -291,15 +293,17 @@ namespace SqlSugar //Step 6: Drop the temporary column this.DropColumn(tableName, tempColumn); - // Commit the transaction - this.Context.Ado.CommitTran(); + if (isTran) + // Commit the transaction + this.Context.Ado.CommitTran(); return true; } catch (Exception) { - // Handle exceptions, log, or rollback the transaction if necessary - this.Context.Ado.RollbackTran(); + if (isTran) + // Handle exceptions, log, or rollback the transaction if necessary + this.Context.Ado.RollbackTran(); // Log the exception or throw it again based on your requirements throw; }