diff --git a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index 3e31d8901..b8219fc99 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -234,6 +234,15 @@ namespace SqlSugar } return this; } + public IDeleteable WhereIF(bool isWhere, Expression> expression) + { + Check.ExceptionEasy(!StaticConfig.EnableAllWhereIF, "Need to program startup configuration StaticConfig. EnableAllWhereIF = true; Tip: This operation is very risky if there are no conditions it is easy to update the entire table", " 需要程序启动时配置StaticConfig.EnableAllWhereIF=true; 提示:该操作存在很大的风险如果没有条件很容易将整个表全部更新"); + if (isWhere) + { + return Where(expression); + } + return this; + } public IDeleteable Where(Expression> expression) { var expResult = DeleteBuilder.GetExpressionValue(expression, ResolveExpressType.WhereSingle); diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 70eb62613..384ccf167 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -831,7 +831,15 @@ namespace SqlSugar SetColumns(columns); return this; } - + public IUpdateable WhereIF(bool isWhere, Expression> expression) + { + Check.ExceptionEasy(!StaticConfig.EnableAllWhereIF, "Need to program startup configuration StaticConfig. EnableAllWhereIF = true; Tip: This operation is very risky if there are no conditions it is easy to update the entire table", " 需要程序启动时配置StaticConfig.EnableAllWhereIF=true; 提示:该操作存在很大的风险如果没有条件很容易将整个表全部更新"); + if (isWhere) + { + return Where(expression); + } + return this; + } public IUpdateable Where(Expression> expression) { Check.Exception(UpdateObjectNotWhere()&&UpdateObjs.Length > 1, ErrorMessage.GetThrowMessage("update List no support where","集合更新不支持Where请使用WhereColumns")); diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs index 2d52c56df..34fb2bedf 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs @@ -26,7 +26,7 @@ namespace SqlSugar public static Func> SplitTableGetTablesFunc; public static bool Check_StringIdentity = true; - + public static bool EnableAllWhereIF = false; public static Func Check_FieldFunc; public static Type DynamicExpressionParserType; } diff --git a/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs b/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs index 36239acde..100c96b10 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs @@ -20,6 +20,7 @@ namespace SqlSugar IDeleteable AsType(Type tableNameType); IDeleteable With(string lockString); IDeleteable Where(T deleteObj); + IDeleteable WhereIF(bool isWhere, Expression> expression); IDeleteable Where(Expression> expression); IDeleteable Where(List deleteObjs); DeleteablePage PageSize(int pageSize); diff --git a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs index c2196a5ed..11b64f88e 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs @@ -32,6 +32,7 @@ namespace SqlSugar IUpdateable Where(Expression> expression); + IUpdateable WhereIF(bool isWhere,Expression> expression); IUpdateable Where(string whereSql,object parameters=null); /// ///