From 0e7cd00873248f28a2b45daaa99ccce879f006cb Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 2 Sep 2022 21:45:38 +0800 Subject: [PATCH] =?UTF-8?q?Add=20constraints=20=EF=BC=88Updateable?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs | 9 +++++++++ .../Abstract/UpdateProvider/UpdateableProvider.cs | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs index 44f01fb18..d3f703eb5 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs @@ -32,6 +32,7 @@ namespace SqlSugar } private string _ExecuteCommand() { + CheckWhere(); PreToSql(); AutoRemoveDataCache(); Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions"); @@ -42,6 +43,14 @@ namespace SqlSugar return sql; } + private void CheckWhere() + { + if (UpdateParameterIsNull && UpdateBuilder.WhereValues.IsNullOrEmpty()) + { + Check.ExceptionEasy("Update requires conditions", "更新需要条件 Where"); + } + } + private void _WhereColumn(string columnName) { var columnInfos = columns.Where(it => it.DbColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase) || it.PropertyName.Equals(columnName, StringComparison.OrdinalIgnoreCase)).ToList(); diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index b802d271e..33651ee9c 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -18,6 +18,10 @@ namespace SqlSugar public UpdateBuilder UpdateBuilder { get; set; } public IAdo Ado { get { return Context.Ado; } } public T[] UpdateObjs { get; set; } + /// + /// true : by expression update + /// false: by object update + /// public bool UpdateParameterIsNull { get; set; } public bool IsMappingTable { get { return this.Context.MappingTables != null && this.Context.MappingTables.Any(); } } public bool IsMappingColumns { get { return this.Context.MappingColumns != null && this.Context.MappingColumns.Any(); } }