From b526c3bfc1f02c4a460058e1d0abec266a9fef7d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 12 Jan 2023 19:59:50 +0800 Subject: [PATCH] Add db.Updateable.EnableQueryFilter --- .../UpdateProvider/UpdateableProvider.cs | 20 +++++++++++++++++++ Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs | 1 + 2 files changed, 21 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 46542b4db..152644c1c 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -382,6 +382,26 @@ namespace SqlSugar #endregion #region Update by expression + public IUpdateable EnableQueryFilter() + { + try + { + ThrowUpdateByObject(); + } + catch + { + Check.ExceptionEasy("Updateable(obj) no support, use Updateable().SetColumn ", "更新过滤器只能用在表达式方式更新 ,更新分为实体更新和表达式更新 。正确用法 Updateable().SetColum(..).Where(..)"); + } + var queryable = this.Context.Queryable(); + queryable.QueryBuilder.LambdaExpressions.ParameterIndex = 1000; + var sqlable = queryable.ToSql(); + var whereInfos = Regex.Split(sqlable.Key, " Where ", RegexOptions.IgnoreCase); + if (whereInfos.Length > 1) + { + this.Where(whereInfos.Last(), sqlable.Value); + } + return this; + } public IUpdateable SetColumns(string fieldName, object fieldValue) { ThrowUpdateByObject(); diff --git a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs index 2c1c9393f..791eb691f 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs @@ -103,5 +103,6 @@ namespace SqlSugar void AddQueue(); SplitTableUpdateProvider SplitTable(Func, IEnumerable> getTableNamesFunc); SplitTableUpdateByObjectProvider SplitTable(); + IUpdateable EnableQueryFilter(); } }