CodeFirst Entity Add DataType

This commit is contained in:
sunkaixuan
2017-07-03 02:07:35 +08:00
parent bdf758c16f
commit 7b49bd15db
5 changed files with 21 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ namespace OrmTest.Demo
[SugarColumn(IsNullable = true,Length =10)]
public string IsOk { get; set; }
public Guid Guid { get; set; }
[SugarColumn(ColumnDataType ="int")]
public decimal Decimal { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? DateTime { get; set; }

View File

@@ -113,7 +113,7 @@ namespace SqlSugar
.Where(ec => !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
.Where(ec =>
dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
&& ((ec.Length != dc.Length &&!PubMethod.GetUnderType(ec.PropertyInfo).IsEnum()&& PubMethod.GetUnderType(ec.PropertyInfo).IsIn(PubConst.StringType)) ||
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(PubConst.StringType)) ||
ec.IsNullable != dc.IsNullable ||
IsSamgeType(ec, dc)))).ToList();
var renameColumns = entityColumns
@@ -223,9 +223,13 @@ namespace SqlSugar
ColumnDescription = item.ColumnDescription,
Length = item.Length
};
if (propertyType.IsEnum())
if (!string.IsNullOrEmpty(item.DataType))
{
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length>9?PubConst.LongType.Name:PubConst.IntType.Name);
result.DataType = item.DataType;
}
else if (propertyType.IsEnum())
{
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? PubConst.LongType.Name : PubConst.IntType.Name);
}
else
{
@@ -236,6 +240,10 @@ namespace SqlSugar
protected virtual bool IsSamgeType(EntityColumnInfo ec, DbColumnInfo dc)
{
if (!string.IsNullOrEmpty(ec.DataType))
{
return ec.DataType != dc.DataType;
}
var propertyType = PubMethod.GetUnderType(ec.PropertyInfo);
var properyTypeName = string.Empty;
if (propertyType.IsEnum())

View File

@@ -122,6 +122,7 @@ namespace SqlSugar
column.IsNullable = sugarColumn.IsNullable;
column.Length = sugarColumn.Length;
column.OldDbColumnName = sugarColumn.OldColumnName;
column.DataType = sugarColumn.ColumnDataType;
}
else
{

View File

@@ -22,5 +22,6 @@ namespace SqlSugar
public string EntityName { get; set; }
public string DbTableName { get; set; }
public bool IsIgnore { get; set; }
public string DataType { get; set; }
}
}

View File

@@ -79,7 +79,13 @@ namespace SqlSugar
get { return _OldColumnName; }
set { _OldColumnName = value; }
}
private string _ColumnDataType;
public string ColumnDataType
{
get { return _ColumnDataType; }
set { _ColumnDataType = value; }
}
}
}