Browse Source

Update MySql

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
a4e9026de5
  1. 2
      Src/Asp.Net/MySqlTest/Demos/5_CodeFirst.cs
  2. 19
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  3. 17
      Src/Asp.Net/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs
  4. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

2
Src/Asp.Net/MySqlTest/Demos/5_CodeFirst.cs

@ -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; }

19
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -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)
{

17
Src/Asp.Net/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs

@ -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);
}
}
}

4
Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

@ -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

Loading…
Cancel
Save