Add db.Updateable.in

This commit is contained in:
sunkaixuan
2024-01-19 20:11:08 +08:00
parent 246ef3cf85
commit 5b433d9a80
2 changed files with 9 additions and 1 deletions

View File

@@ -870,6 +870,14 @@ namespace SqlSugar
SetColumns(columns); SetColumns(columns);
return this; return this;
} }
public IUpdateable<T> In<PkType>(Expression<Func<T, object>> inField, ISugarQueryable<PkType> childQueryExpression)
{
var lamResult = UpdateBuilder.GetExpressionValue(inField, ResolveExpressType.FieldSingle);
var fieldName = lamResult.GetResultString();
var sql = childQueryExpression.ToSql();
Where($" {fieldName} IN ( SELECT {fieldName} FROM ( {sql.Key} ) SUBDEL) ", sql.Value);
return this;
}
public IUpdateable<T> WhereIF(bool isWhere, Expression<Func<T, bool>> expression) 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; 提示:该操作存在很大的风险如果没有条件很容易将整个表全部更新"); 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; 提示:该操作存在很大的风险如果没有条件很容易将整个表全部更新");

View File

@@ -29,7 +29,7 @@ namespace SqlSugar
IUpdateable<T> AS(string tableName); IUpdateable<T> AS(string tableName);
IUpdateable<T> AsType(Type tableNameType); IUpdateable<T> AsType(Type tableNameType);
IUpdateable<T> With(string lockString); IUpdateable<T> With(string lockString);
IUpdateable<T> In<PkType>(Expression<Func<T, object>> inField, ISugarQueryable<PkType> childQueryExpression);
IUpdateable<T> Where(Expression<Func<T, bool>> expression); IUpdateable<T> Where(Expression<Func<T, bool>> expression);
IUpdateable<T> WhereIF(bool isWhere,Expression<Func<T, bool>> expression); IUpdateable<T> WhereIF(bool isWhere,Expression<Func<T, bool>> expression);