mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
CodeFirst Entity Add DataType
This commit is contained in:
@@ -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; }
|
||||
|
@@ -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())
|
||||
|
@@ -122,6 +122,7 @@ namespace SqlSugar
|
||||
column.IsNullable = sugarColumn.IsNullable;
|
||||
column.Length = sugarColumn.Length;
|
||||
column.OldDbColumnName = sugarColumn.OldColumnName;
|
||||
column.DataType = sugarColumn.ColumnDataType;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
@@ -79,7 +79,13 @@ namespace SqlSugar
|
||||
get { return _OldColumnName; }
|
||||
set { _OldColumnName = value; }
|
||||
}
|
||||
|
||||
|
||||
private string _ColumnDataType;
|
||||
public string ColumnDataType
|
||||
{
|
||||
get { return _ColumnDataType; }
|
||||
set { _ColumnDataType = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user