mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-29 09:54:44 +08:00
PgSql CodeFirst alter column bug
This commit is contained in:
@@ -38,9 +38,9 @@ namespace OrmTest
|
|||||||
Ado();
|
Ado();
|
||||||
Queryable();
|
Queryable();
|
||||||
QueryableAsync();
|
QueryableAsync();
|
||||||
Thread();
|
//Thread();
|
||||||
Thread2();
|
//Thread2();
|
||||||
Thread3();
|
//Thread3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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" })]
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user