From 8eadde930f4b1233b634ccf4b9e591d484f251e9 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Wed, 2 Sep 2020 19:20:41 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20string=20IsNullable=20?= =?UTF-8?q?=3D=20false=20=E6=97=B6=E6=8F=92=E5=85=A5=20null=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BD=AC=E4=B8=BA=20""=20#445=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.DbContext/FreeSql.DbContext.xml | 9 +++++++++ .../Internal/CommonProvider/InsertOrUpdateProvider.cs | 2 ++ FreeSql/Internal/CommonProvider/InsertProvider.cs | 2 ++ FreeSql/Internal/CommonProvider/UpdateProvider.cs | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 9c6cd88b..743835e4 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -532,5 +532,14 @@ + + + 批量注入 Repository,可以参考代码自行调整 + + + + + + diff --git a/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs b/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs index 1d8a13c4..92c5b536 100644 --- a/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs +++ b/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs @@ -92,6 +92,8 @@ namespace FreeSql.Internal.CommonProvider if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false) changedDict.Add(col.Attribute.Name, true); } + if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false) + col.SetValue(data, val = ""); } } diff --git a/FreeSql/Internal/CommonProvider/InsertProvider.cs b/FreeSql/Internal/CommonProvider/InsertProvider.cs index 30495e56..1d394457 100644 --- a/FreeSql/Internal/CommonProvider/InsertProvider.cs +++ b/FreeSql/Internal/CommonProvider/InsertProvider.cs @@ -171,6 +171,8 @@ namespace FreeSql.Internal.CommonProvider col.SetValue(data, val = FreeUtil.NewMongodbId()); } } + if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false) + col.SetValue(data, val = ""); } } diff --git a/FreeSql/Internal/CommonProvider/UpdateProvider.cs b/FreeSql/Internal/CommonProvider/UpdateProvider.cs index b6a24926..1de0b502 100644 --- a/FreeSql/Internal/CommonProvider/UpdateProvider.cs +++ b/FreeSql/Internal/CommonProvider/UpdateProvider.cs @@ -359,6 +359,8 @@ namespace FreeSql.Internal.CommonProvider if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false) changedDict.Add(col.Attribute.Name, true); } + if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false) + col.SetValue(data, val = ""); } } } @@ -379,6 +381,8 @@ namespace FreeSql.Internal.CommonProvider if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false) changedDict.Add(col.Attribute.Name, true); } + if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false) + col.SetValue(data, val = ""); } }