Browse Source

Update mysql codefirst time default value

pull/14/head
sunkaixuan 3 years ago
parent
commit
70ac668407
  1. 17
      Src/Asp.Net/MySqlTest/UnitTest/UnitCustom01.cs
  2. 3
      Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

17
Src/Asp.Net/MySqlTest/UnitTest/UnitCustom01.cs

@ -22,6 +22,10 @@ namespace OrmTest
IsAutoCloseConnection = true
});
ssc.Aop.OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
};
ssc.CodeFirst.InitTables<Student>();
var expMethods = new List<SqlFuncExternal>();
@ -75,9 +79,22 @@ namespace OrmTest
}
ssc.CodeFirst.InitTables<unittest1231sdaa>();
ssc.CodeFirst.InitTables<unittest1231sdaa2>();
}
}
public class unittest1231sdaa
{
[SugarColumn(IndexGroupNameList = new string[] { "index3" }, ColumnDataType = "DATETIME(6)", DefaultValue = "CURRENT_TIMESTAMP(6)")]
public DateTime update_time { get; set; }
}
public class unittest1231sdaa2
{
[SugarColumn(IndexGroupNameList = new string[] { "index3" }, ColumnDataType = "DATETIME", DefaultValue = "CURRENT_TIMESTAMP")]
public DateTime update_time { get; set; }
}
[SugarTable("unitstudent1111")]
public class Student
{

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

@ -438,7 +438,8 @@ namespace SqlSugar
{
string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} default {2}";
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType);
var value = Regex.Match(defaultValue, @"\(\d\)$").Value;
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType+ value);
this.Context.Ado.ExecuteCommand(sql);
return true;
}

Loading…
Cancel
Save