MYSQL CODE FIRST BUG

This commit is contained in:
sunkaixuan
2018-05-05 16:49:35 +08:00
parent f524c73ae2
commit 66e5b219a0
3 changed files with 36 additions and 6 deletions

View File

@@ -257,8 +257,8 @@ namespace SqlSugar
{
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType;
string dataSize = GetSize(columnInfo);
string dataType = columnInfo.DataType;
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = null;
@@ -277,6 +277,11 @@ namespace SqlSugar
{
dataSize = item.Length > 0 ? string.Format("({0})", "max") : null;
}
else if (item.Length == 0 && item.DecimalDigits > 0)
{
item.Length = 10;
dataSize = string.Format("({0},{1})", item.Length, item.DecimalDigits);
}
else if (item.Length > 0 && item.DecimalDigits == 0)
{
dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;

View File

@@ -35,7 +35,8 @@ namespace SqlSugar
IsNullable = item.IsNullable,
DefaultValue = item.DefaultValue,
ColumnDescription = item.ColumnDescription,
Length = item.Length
Length = item.Length,
DecimalDigits=item.DecimalDigits
};
GetDbType(item, propertyType, result);
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)

View File

@@ -208,11 +208,9 @@ namespace SqlSugar
foreach (var item in columns)
{
string columnName = item.DbColumnName;
string dataSize = "";
dataSize = GetSize(item);
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 nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
@@ -222,6 +220,32 @@ namespace SqlSugar
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
return tableString;
}
protected override string GetSize(DbColumnInfo item)
{
string dataSize = null;
var isMax = item.Length > 4000 || item.Length == -1;
if (isMax)
{
dataSize="";
item.DataType = "longtext";
}
else if (item.Length > 0 && item.DecimalDigits == 0)
{
dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
}
else if (item.Length == 0 && item.DecimalDigits > 0)
{
item.Length = 10;
dataSize = string.Format("({0},{1})", item.Length, item.DecimalDigits);
}
else if (item.Length > 0 && item.DecimalDigits > 0)
{
dataSize = item.Length > 0 ? string.Format("({0},{1})", item.Length, item.DecimalDigits) : null;
}
return dataSize;
}
public override bool IsAnyConstraint(string constraintName)
{
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");