This commit is contained in:
sunkaixuan 2017-08-26 01:57:24 +08:00
parent a1a8298fca
commit 96d7efdfab
4 changed files with 29 additions and 10 deletions

View File

@ -22,8 +22,10 @@ namespace OrmTest.Demo
public DateTime? DateTime { get; set; } public DateTime? DateTime { get; set; }
[SugarColumn(IsNullable = true,OldColumnName = "Dob")] [SugarColumn(IsNullable = true,OldColumnName = "Dob")]
public double? Dob2 { get; set; } public double? Dob2 { get; set; }
[SugarColumn(Length =110)] [SugarColumn(Length =11000)]
public string A1 { get; set; } public string A1 { get; set; }
[SugarColumn(Length = 18,DecimalDigits=2)]
public decimal Dec { get; set; }
} }
public class CodeTable2 { public class CodeTable2 {
public int Id { get; set; } public int Id { get; set; }

View File

@ -238,10 +238,7 @@ namespace SqlSugar
{ {
string columnName = this.SqlBuilder.GetTranslationTableName(item.DbColumnName); string columnName = this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
string dataType = item.DataType; string dataType = item.DataType;
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null; string dataSize = GetSize(item);
if (item.Length>4000|| item.Length==-1) {
dataSize = string.Format("({0})","max");
}
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull; string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null; string primaryKey = null;
string identity = item.IsIdentity ? this.CreateTableIdentity : null; string identity = item.IsIdentity ? this.CreateTableIdentity : null;
@ -251,12 +248,31 @@ namespace SqlSugar
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray)); string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
return tableString; return tableString;
} }
protected virtual string GetSize(DbColumnInfo item)
{
string dataSize = null;
var isMax = item.Length > 4000 || item.Length == -1;
if (isMax) {
dataSize = item.Length > 0 ? string.Format("({0})", "max") : null;
}
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)
{
dataSize = item.Length > 0 ? string.Format("({0},{1})", item.Length, item.DecimalDigits) : null;
}
return dataSize;
}
protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo) protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo)
{ {
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName); string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName); tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType; string dataType = columnInfo.DataType;
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null; string dataSize = GetSize(columnInfo);
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull; string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null; string primaryKey = null;
string identity = null; string identity = null;
@ -268,7 +284,7 @@ namespace SqlSugar
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName); string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName); tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType; string dataType = columnInfo.DataType;
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null; string dataSize = GetSize(columnInfo);
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull; string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null; string primaryKey = null;
string identity = null; string identity = null;

View File

@ -19,5 +19,6 @@ namespace SqlSugar
public bool IsIdentity { get; set; } public bool IsIdentity { get; set; }
public bool IsPrimarykey { get; set; } public bool IsPrimarykey { get; set; }
public object Value { get; set; } public object Value { get; set; }
public int DecimalDigits { get; set; }
} }
} }

View File

@ -87,8 +87,8 @@ namespace SqlSugar
set { _ColumnDataType = value; } set { _ColumnDataType = value; }
} }
private int? _DecimalDigits; private int _DecimalDigits;
private int? DecimalDigits { public int DecimalDigits {
get { return _DecimalDigits; } get { return _DecimalDigits; }
set { _DecimalDigits = value; } set { _DecimalDigits = value; }
} }