mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
CodeFirst Entity Add DataType
This commit is contained in:
@@ -16,6 +16,7 @@ namespace OrmTest.Demo
|
|||||||
[SugarColumn(IsNullable = true,Length =10)]
|
[SugarColumn(IsNullable = true,Length =10)]
|
||||||
public string IsOk { get; set; }
|
public string IsOk { get; set; }
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
|
[SugarColumn(ColumnDataType ="int")]
|
||||||
public decimal Decimal { get; set; }
|
public decimal Decimal { get; set; }
|
||||||
[SugarColumn(IsNullable = true)]
|
[SugarColumn(IsNullable = true)]
|
||||||
public DateTime? DateTime { get; set; }
|
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.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||||
.Where(ec =>
|
.Where(ec =>
|
||||||
dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
|
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 ||
|
ec.IsNullable != dc.IsNullable ||
|
||||||
IsSamgeType(ec, dc)))).ToList();
|
IsSamgeType(ec, dc)))).ToList();
|
||||||
var renameColumns = entityColumns
|
var renameColumns = entityColumns
|
||||||
@@ -223,9 +223,13 @@ namespace SqlSugar
|
|||||||
ColumnDescription = item.ColumnDescription,
|
ColumnDescription = item.ColumnDescription,
|
||||||
Length = item.Length
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -236,6 +240,10 @@ namespace SqlSugar
|
|||||||
|
|
||||||
protected virtual bool IsSamgeType(EntityColumnInfo ec, DbColumnInfo dc)
|
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 propertyType = PubMethod.GetUnderType(ec.PropertyInfo);
|
||||||
var properyTypeName = string.Empty;
|
var properyTypeName = string.Empty;
|
||||||
if (propertyType.IsEnum())
|
if (propertyType.IsEnum())
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ namespace SqlSugar
|
|||||||
column.IsNullable = sugarColumn.IsNullable;
|
column.IsNullable = sugarColumn.IsNullable;
|
||||||
column.Length = sugarColumn.Length;
|
column.Length = sugarColumn.Length;
|
||||||
column.OldDbColumnName = sugarColumn.OldColumnName;
|
column.OldDbColumnName = sugarColumn.OldColumnName;
|
||||||
|
column.DataType = sugarColumn.ColumnDataType;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ namespace SqlSugar
|
|||||||
public string EntityName { get; set; }
|
public string EntityName { get; set; }
|
||||||
public string DbTableName { get; set; }
|
public string DbTableName { get; set; }
|
||||||
public bool IsIgnore { get; set; }
|
public bool IsIgnore { get; set; }
|
||||||
|
public string DataType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,13 @@ namespace SqlSugar
|
|||||||
get { return _OldColumnName; }
|
get { return _OldColumnName; }
|
||||||
set { _OldColumnName = value; }
|
set { _OldColumnName = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string _ColumnDataType;
|
||||||
|
public string ColumnDataType
|
||||||
|
{
|
||||||
|
get { return _ColumnDataType; }
|
||||||
|
set { _ColumnDataType = value; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user