mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update MySql
This commit is contained in:
parent
3b7b9c2de1
commit
601adfdef4
@ -9,14 +9,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public override void NoExistLogic(EntityInfo entityInfo)
|
public override void NoExistLogic(EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
var tableName = base.GetTableName(entityInfo);
|
var tableName = GetTableName(entityInfo);
|
||||||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||||
if (entityInfo.Columns.IsValuable())
|
if (entityInfo.Columns.IsValuable())
|
||||||
{
|
{
|
||||||
foreach (var item in entityInfo.Columns)
|
foreach (var item in entityInfo.Columns)
|
||||||
{
|
{
|
||||||
DbColumnInfo dbColumnInfo = base.EntityColumnToDbColumn(entityInfo, tableName, item);
|
DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||||
columns.Add(dbColumnInfo);
|
columns.Add(dbColumnInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "ALTER TABLE {0} ADD CONSTRAINT {1} PRIMARY KEY({2})";
|
return "ALTER TABLE {0} ADD PRIMARY KEY({2}) /*{1}*/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string AddColumnToTableSql
|
protected override string AddColumnToTableSql
|
||||||
@ -81,7 +81,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "CREATE TABLE {0}(\r\n{1}, PRIMARY KEY (`{2}`))";
|
return "CREATE TABLE {0}(\r\n{1} $PrimaryKey)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string CreateTableColumn
|
protected override string CreateTableColumn
|
||||||
@ -189,7 +189,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return base.CreateTable(tableName,columns);
|
string sql = GetCreateTableSql(tableName, columns);
|
||||||
|
string primaryKeyInfo = null;
|
||||||
|
if (columns.Any(it => it.IsIdentity)) {
|
||||||
|
primaryKeyInfo =string.Format( ", Primary key({0})",string.Join(",",columns.Where(it=>it.IsIdentity).Select(it=>this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
|
||||||
|
|
||||||
|
}
|
||||||
|
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
|
||||||
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
||||||
{
|
{
|
||||||
@ -199,6 +207,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
string columnName = item.DbColumnName;
|
string columnName = item.DbColumnName;
|
||||||
string dataType = item.DataType;
|
string dataType = item.DataType;
|
||||||
|
if (dataType == "varchar"&& item.Length==0) {
|
||||||
|
item.Length = 1;
|
||||||
|
}
|
||||||
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
||||||
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
||||||
string primaryKey = null;
|
string primaryKey = null;
|
||||||
@ -206,9 +217,10 @@ namespace SqlSugar
|
|||||||
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName), dataType, dataSize, nullType, primaryKey, identity);
|
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName), dataType, dataSize, nullType, primaryKey, identity);
|
||||||
columnArray.Add(addItem);
|
columnArray.Add(addItem);
|
||||||
}
|
}
|
||||||
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray), columns.First(it=>it.IsPrimarykey).DbColumnName);
|
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
||||||
return tableString;
|
return tableString;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user