mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
PgSql CodeFirst alter column bug
This commit is contained in:
parent
df578c033e
commit
2dcd4ca481
@ -38,9 +38,9 @@ namespace OrmTest
|
||||
Ado();
|
||||
Queryable();
|
||||
QueryableAsync();
|
||||
Thread();
|
||||
Thread2();
|
||||
Thread3();
|
||||
//Thread();
|
||||
//Thread2();
|
||||
//Thread3();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,24 @@ namespace OrmTest
|
||||
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
|
||||
Db.DbMaintenance.DropTable("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
|
||||
{
|
||||
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
|
||||
|
@ -240,6 +240,30 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#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>
|
||||
///by current connection string
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user