From c0b6d6e9f16cc3a6f23a5f8f3f0b95abf1f48b2d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 20 Apr 2019 20:48:22 +0800 Subject: [PATCH] Remove Insert null validation --- .../InsertableProvider/InsertableProvider.cs | 16 ++++++++++++++++ Src/Asp.Net/SqlSugar/SqlSugarClient.cs | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 0173fa544..07249e96c 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -40,6 +40,10 @@ namespace SqlSugar } public virtual int ExecuteCommand() { + if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) + { + return 0; + } if (InsertBuilder.DbColumnInfoList.HasValue()) { var pks = GetPrimaryKeys(); @@ -76,6 +80,10 @@ namespace SqlSugar } public virtual int ExecuteReturnIdentity() { + if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) + { + return 0; + } InsertBuilder.IsReturnIdentity = true; PreToSql(); AutoRemoveDataCache(); @@ -88,6 +96,10 @@ namespace SqlSugar } public virtual long ExecuteReturnBigIdentity() { + if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) + { + return 0; + } InsertBuilder.IsReturnIdentity = true; PreToSql(); AutoRemoveDataCache(); @@ -353,6 +365,10 @@ namespace SqlSugar } private void SetInsertItemByEntity(int i, T item, List insertItem) { + if (item == null) + { + return; + } foreach (var column in EntityInfo.Columns) { if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue; diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 6d266b049..cf6f7118a 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -450,7 +450,11 @@ namespace SqlSugar } public virtual IInsertable Insertable(List insertObjs) where T : class, new() { - Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null"); + if (insertObjs == null|| insertObjs.IsNullOrEmpty()) + { + insertObjs = new List(); + insertObjs.Add(default(T)); + } return this.Context.Insertable(insertObjs.ToArray()); } public virtual IInsertable Insertable(T insertObj) where T : class, new()