Skip to content

Commit a8d1db8

Browse files
2881028810
authored andcommitted
- 调整 ColumnAttribute IsNullable 对 int/long 等值类型也可生效;#384
1 parent de86beb commit a8d1db8

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

Examples/base_entity/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static void Main(string[] args)
9797
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
9898
#endregion
9999

100+
var sql = fsql.CodeFirst.GetComparisonDDLStatements(typeof(EMSServerModel.Model.User), "testxsx001");
101+
100102
var test01 = EMSServerModel.Model.User.Select.IncludeMany(a => a.Roles).ToList();
101103
var test02 = EMSServerModel.Model.UserRole.Select.ToList();
102104
var test01tb = EMSServerModel.Model.User.Orm.CodeFirst.GetTableByEntity(typeof(EMSServerModel.Model.User));

Examples/base_entity/Test01/User.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ public partial class User : BaseEntity<User> {
9494
/// <summary>
9595
/// 职务编号
9696
/// </summary>
97+
[JsonProperty, Column(IsNullable = true)]
98+
public long TitleId { get; set; }
99+
97100
[JsonProperty]
98-
public long? TitleId { get; set; }
101+
public long TitleId2 { get; set; }
102+
99103

100-
101104
///// <summary>
102105
///// 创建时间
103106
///// </summary>

FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessCodeFirstTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void CurdAllField()
245245
var itemstb = select.ToDataTable();
246246
}
247247

248-
[Table(Name = "tb_alltype")]
248+
[Table(Name = "tb_alltype_insert")]
249249
class TableAllType
250250
{
251251
[Column(IsIdentity = true, IsPrimary = true)]

FreeSql/Internal/UtilsExpressionTree.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
101101
continue;
102102
}
103103
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤
104+
var colattrIsNullable = colattr?._IsNullable;
105+
var colattrIsNull = colattr == null;
104106
if (colattr == null)
105107
colattr = new ColumnAttribute
106108
{
@@ -119,6 +121,8 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
119121
else
120122
colattr.DbType = colattr.DbType.ToUpper();
121123

124+
if (colattrIsNull == false && colattrIsNullable == true) colattr.DbType = colattr.DbType.Replace("NOT NULL", "");
125+
if (colattrIsNull == false && colattrIsNullable == false) colattr.DbType = Regex.Replace(colattr.DbType, @"\bNULL\b", "").Trim() + " NOT NULL";
122126
if (colattr._IsNullable == null && tp != null && tp.isnullable == null) colattr.IsNullable = tp.dbtypeFull.Contains("NOT NULL") == false;
123127
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
124128
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;

0 commit comments

Comments
 (0)