- 调整 ColumnAttribute IsNullable 对 int/long 等值类型也可生效;#384

This commit is contained in:
28810 2020-07-29 13:19:47 +08:00
parent de86beba4f
commit a8d1db8614
4 changed files with 13 additions and 4 deletions

View File

@ -97,6 +97,8 @@ namespace base_entity
BaseEntity.Initialization(fsql, () => _asyncUow.Value); BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion #endregion
var sql = fsql.CodeFirst.GetComparisonDDLStatements(typeof(EMSServerModel.Model.User), "testxsx001");
var test01 = EMSServerModel.Model.User.Select.IncludeMany(a => a.Roles).ToList(); var test01 = EMSServerModel.Model.User.Select.IncludeMany(a => a.Roles).ToList();
var test02 = EMSServerModel.Model.UserRole.Select.ToList(); var test02 = EMSServerModel.Model.UserRole.Select.ToList();
var test01tb = EMSServerModel.Model.User.Orm.CodeFirst.GetTableByEntity(typeof(EMSServerModel.Model.User)); var test01tb = EMSServerModel.Model.User.Orm.CodeFirst.GetTableByEntity(typeof(EMSServerModel.Model.User));

View File

@ -94,8 +94,11 @@ namespace EMSServerModel.Model
/// <summary> /// <summary>
/// 职务编号 /// 职务编号
/// </summary> /// </summary>
[JsonProperty, Column(IsNullable = true)]
public long TitleId { get; set; }
[JsonProperty] [JsonProperty]
public long? TitleId { get; set; } public long TitleId2 { get; set; }
///// <summary> ///// <summary>

View File

@ -245,7 +245,7 @@ namespace FreeSql.Tests.MsAccess
var itemstb = select.ToDataTable(); var itemstb = select.ToDataTable();
} }
[Table(Name = "tb_alltype")] [Table(Name = "tb_alltype_insert")]
class TableAllType class TableAllType
{ {
[Column(IsIdentity = true, IsPrimary = true)] [Column(IsIdentity = true, IsPrimary = true)]

View File

@ -101,6 +101,8 @@ namespace FreeSql.Internal
continue; continue;
} }
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤 if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤
var colattrIsNullable = colattr?._IsNullable;
var colattrIsNull = colattr == null;
if (colattr == null) if (colattr == null)
colattr = new ColumnAttribute colattr = new ColumnAttribute
{ {
@ -119,6 +121,8 @@ namespace FreeSql.Internal
else else
colattr.DbType = colattr.DbType.ToUpper(); colattr.DbType = colattr.DbType.ToUpper();
if (colattrIsNull == false && colattrIsNullable == true) colattr.DbType = colattr.DbType.Replace("NOT NULL", "");
if (colattrIsNull == false && colattrIsNullable == false) colattr.DbType = Regex.Replace(colattr.DbType, @"\bNULL\b", "").Trim() + " NOT NULL";
if (colattr._IsNullable == null && tp != null && tp.isnullable == null) colattr.IsNullable = tp.dbtypeFull.Contains("NOT NULL") == false; if (colattr._IsNullable == null && tp != null && tp.isnullable == null) colattr.IsNullable = tp.dbtypeFull.Contains("NOT NULL") == false;
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false; if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name; if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;