Delete.WhereIF Update.WhereIF

This commit is contained in:
sunkaixuan 2023-09-19 15:19:00 +08:00
parent f43efe3925
commit fe29238456
5 changed files with 21 additions and 2 deletions

View File

@ -234,6 +234,15 @@ namespace SqlSugar
}
return this;
}
public IDeleteable<T> WhereIF(bool isWhere, Expression<Func<T, bool>> 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<T> Where(Expression<Func<T, bool>> expression)
{
var expResult = DeleteBuilder.GetExpressionValue(expression, ResolveExpressType.WhereSingle);

View File

@ -831,7 +831,15 @@ namespace SqlSugar
SetColumns(columns);
return this;
}
public IUpdateable<T> WhereIF(bool isWhere, Expression<Func<T, bool>> 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<T> Where(Expression<Func<T, bool>> expression)
{
Check.Exception(UpdateObjectNotWhere()&&UpdateObjs.Length > 1, ErrorMessage.GetThrowMessage("update List no support where","集合更新不支持Where请使用WhereColumns"));

View File

@ -26,7 +26,7 @@ namespace SqlSugar
public static Func<List<SplitTableInfo>> SplitTableGetTablesFunc;
public static bool Check_StringIdentity = true;
public static bool EnableAllWhereIF = false;
public static Func<string,string> Check_FieldFunc;
public static Type DynamicExpressionParserType;
}

View File

@ -20,6 +20,7 @@ namespace SqlSugar
IDeleteable<T> AsType(Type tableNameType);
IDeleteable<T> With(string lockString);
IDeleteable<T> Where(T deleteObj);
IDeleteable<T> WhereIF(bool isWhere, Expression<Func<T, bool>> expression);
IDeleteable<T> Where(Expression<Func<T, bool>> expression);
IDeleteable<T> Where(List<T> deleteObjs);
DeleteablePage<T> PageSize(int pageSize);

View File

@ -32,6 +32,7 @@ namespace SqlSugar
IUpdateable<T> Where(Expression<Func<T, bool>> expression);
IUpdateable<T> WhereIF(bool isWhere,Expression<Func<T, bool>> expression);
IUpdateable<T> Where(string whereSql,object parameters=null);
/// <summary>
///