mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Update MySql
This commit is contained in:
@@ -13,7 +13,7 @@ namespace OrmTest.Demo
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(Length = 21,OldColumnName = "Name2")]
|
||||
public string Name{ get; set; }
|
||||
[SugarColumn(IsNullable = true,Length =10)]
|
||||
[SugarColumn(IsNullable = true,Length =11)]
|
||||
public string IsOk { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
public decimal Decimal { get; set; }
|
||||
|
@@ -163,13 +163,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (pkDiff || idEntityDiff)
|
||||
{
|
||||
string constraintName = string.Format("PK_{0}_{1}", tableName, item.DbColumnName);
|
||||
if (this.Context.DbMaintenance.IsAnyConstraint(constraintName))
|
||||
this.Context.DbMaintenance.DropConstraint(tableName, constraintName);
|
||||
this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName);
|
||||
this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
if (item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
ChangeKey(entityInfo, tableName, item);
|
||||
}
|
||||
}
|
||||
if (isChange && IsBackupTable)
|
||||
@@ -179,6 +173,17 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
string constraintName = string.Format("PK_{0}_{1}", tableName, item.DbColumnName);
|
||||
if (this.Context.DbMaintenance.IsAnyConstraint(constraintName))
|
||||
this.Context.DbMaintenance.DropConstraint(tableName, constraintName);
|
||||
this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName);
|
||||
this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
if (item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
|
||||
protected virtual void ConvertColumns(List<DbColumnInfo> dbColumns)
|
||||
{
|
||||
|
||||
|
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlCodeFirst:CodeFirstProvider
|
||||
public class MySqlCodeFirst : CodeFirstProvider
|
||||
{
|
||||
public override void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
@@ -37,7 +37,8 @@ namespace SqlSugar
|
||||
ColumnDescription = item.ColumnDescription,
|
||||
Length = item.Length
|
||||
};
|
||||
if (result.DataType.Equals("varchar",StringComparison.CurrentCultureIgnoreCase)&& result.Length == 0) {
|
||||
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)
|
||||
{
|
||||
result.Length = 1;
|
||||
}
|
||||
return result;
|
||||
@@ -47,10 +48,20 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in dbColumns)
|
||||
{
|
||||
if (item.DataType == "DateTime") {
|
||||
if (item.DataType == "DateTime")
|
||||
{
|
||||
item.Length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
this.Context.DbMaintenance.UpdateColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
if (!item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.DropConstraint(tableName,null);
|
||||
if (item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -104,7 +104,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT TOP {0} * INTO {1} FROM {2}";
|
||||
return "SELECT * INTO {1} FROM {2} limit 0,{0}";
|
||||
}
|
||||
}
|
||||
protected override string DropTableSql
|
||||
@@ -125,7 +125,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
|
||||
return "ALTER TABLE {0} drop primary key;";
|
||||
}
|
||||
}
|
||||
protected override string RenameColumnSql
|
||||
|
Reference in New Issue
Block a user