- 优化 枚举属性的默认值容错,枚举下标不存在 0 的时候,mysql 迁移结构默认值报错;

This commit is contained in:
28810
2019-10-09 16:56:24 +08:00
parent 236d03f98c
commit 1f2d4abdc7
3 changed files with 58 additions and 0 deletions

View File

@ -153,6 +153,19 @@ namespace FreeSql.Internal
continue;
}
if (entityDefault != null) colattr.DbDefautValue = trytb.Properties[p.Name].GetValue(entityDefault);
if (p.PropertyType.IsEnum)
{
var isEqualsEnumValue = false;
var enumValues = Enum.GetValues(p.PropertyType);
for (var a = 0; a < enumValues.Length; a++)
if (object.Equals(colattr.DbDefautValue, enumValues.GetValue(a)))
{
isEqualsEnumValue = true;
break;
}
if (isEqualsEnumValue == false)
colattr.DbDefautValue = enumValues.Length > 0 ? enumValues.GetValue(0) : null;
}
if (colattr.DbDefautValue != null && p.PropertyType != colattr.MapType) colattr.DbDefautValue = Utils.GetDataReaderValue(colattr.MapType, colattr.DbDefautValue);
if (colattr.DbDefautValue == null) colattr.DbDefautValue = tp?.defaultValue;
if (colattr.IsNullable == false && colattr.DbDefautValue == null)