- FreeSql.Generator 类型映射容错判断;

This commit is contained in:
28810
2019-12-22 01:15:38 +08:00
parent a17917e172
commit 35829f9010
3 changed files with 38 additions and 12 deletions

View File

@ -66,19 +66,23 @@ public class RazorModel {
if (GetCsName(col.Name) != col.Name)
sb.Add("Name = \"" + col.Name + "\"");
var dbinfo = fsql.CodeFirst.GetDbInfo(col.CsType);
if (dbinfo != null && dbinfo.Value.dbtypeFull.Replace("NOT NULL", "").Trim() != col.DbTypeTextFull)
sb.Add("DbType = \"" + col.DbTypeTextFull + "\"");
if (col.IsPrimary)
sb.Add("IsPrimary = true");
if (col.IsIdentity)
sb.Add("IsIdentity = true");
if (col.CsType != null)
{
var dbinfo = fsql.CodeFirst.GetDbInfo(col.CsType);
if (dbinfo != null && dbinfo.Value.dbtypeFull.Replace("NOT NULL", "").Trim() != col.DbTypeTextFull)
sb.Add("DbType = \"" + col.DbTypeTextFull + "\"");
if (col.IsPrimary)
sb.Add("IsPrimary = true");
if (col.IsIdentity)
sb.Add("IsIdentity = true");
if (dbinfo != null && dbinfo.Value.isnullable != col.IsNullable) {
if (col.IsNullable && fsql.DbFirst.GetCsType(col).Contains("?") == false && col.CsType.IsValueType)
sb.Add("IsNullable = true");
if (col.IsNullable == false && fsql.DbFirst.GetCsType(col).Contains("?") == true)
sb.Add("IsNullable = false");
if (dbinfo != null && dbinfo.Value.isnullable != col.IsNullable)
{
if (col.IsNullable && fsql.DbFirst.GetCsType(col).Contains("?") == false && col.CsType.IsValueType)
sb.Add("IsNullable = true");
if (col.IsNullable == false && fsql.DbFirst.GetCsType(col).Contains("?") == true)
sb.Add("IsNullable = false");
}
}
if (sb.Any() == false) return null;
return "[Column(" + string.Join(", ", sb) + ")]";