PgSql CodeFirst alter column bug

This commit is contained in:
skx
2021-01-29 20:36:52 +08:00
parent df578c033e
commit 2dcd4ca481
3 changed files with 45 additions and 4 deletions

View File

@@ -38,9 +38,9 @@ namespace OrmTest
Ado(); Ado();
Queryable(); Queryable();
QueryableAsync(); QueryableAsync();
Thread(); //Thread();
Thread2(); //Thread2();
Thread3(); //Thread3();
} }
} }
} }

View File

@@ -13,7 +13,24 @@ namespace OrmTest
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false)) if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1"); Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>(); Db.CodeFirst.InitTables<UnitCodeTest1>();
Db.CodeFirst.InitTables<UnitCodeTest22>();
Db.Insertable(new UnitCodeTest22()).ExecuteCommand();
Db.DbMaintenance.TruncateTable<UnitCodeTest22>();
Db.CodeFirst.InitTables<UnitCodeTest3>();
Db.Insertable(new UnitCodeTest22() { id=1}).ExecuteCommand();
} }
public class UnitCodeTest22 {
[SqlSugar.SugarColumn(IsNullable =true)]
public decimal? id { get; set; }
}
[SqlSugar.SugarTable("UnitCodeTest22")]
public class UnitCodeTest3
{
[SqlSugar.SugarColumn(IsNullable = false)]
public int id { get; set; }
}
public class UnitCodeTest1 public class UnitCodeTest1
{ {
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })] [SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]

View File

@@ -237,9 +237,33 @@ namespace SqlSugar
return "serial"; return "serial";
} }
} }
#endregion #endregion
#region Methods #region Methods
public override bool UpdateColumn(string tableName, DbColumnInfo columnInfo)
{
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
var columnName= this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
string sql = GetUpdateColumnSql(tableName, columnInfo);
this.Context.Ado.ExecuteCommand(sql);
var isnull = columnInfo.IsNullable?" SET NOT NULL ":" DROP NOT NULL ";
this.Context.Ado.ExecuteCommand(string.Format("alter table {0} alter {1} {2}",tableName,columnName, isnull));
return true;
}
protected override string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
{
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataSize = GetSize(columnInfo);
string dataType = columnInfo.DataType;
string nullType = "";
string primaryKey = null;
string identity = null;
string result = string.Format(this.AlterColumnToTableSql, tableName, columnName, dataType, dataSize, nullType, primaryKey, identity);
return result;
}
/// <summary> /// <summary>
///by current connection string ///by current connection string
/// </summary> /// </summary>