Browse Source

Add db.Updateable.EnableQueryFilter

pull/30/head
sunkaixuan 2 years ago
parent
commit
b526c3bfc1
  1. 20
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  2. 1
      Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs

20
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -382,6 +382,26 @@ namespace SqlSugar
#endregion #endregion
#region Update by expression #region Update by expression
public IUpdateable<T> EnableQueryFilter()
{
try
{
ThrowUpdateByObject();
}
catch
{
Check.ExceptionEasy("Updateable<T>(obj) no support, use Updateable<T>().SetColumn ", "更新过滤器只能用在表达式方式更新 ,更新分为实体更新和表达式更新 。正确用法 Updateable<T>().SetColum(..).Where(..)");
}
var queryable = this.Context.Queryable<T>();
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<T> SetColumns(string fieldName, object fieldValue) public IUpdateable<T> SetColumns(string fieldName, object fieldValue)
{ {
ThrowUpdateByObject(); ThrowUpdateByObject();

1
Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs

@ -103,5 +103,6 @@ namespace SqlSugar
void AddQueue(); void AddQueue();
SplitTableUpdateProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc); SplitTableUpdateProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc);
SplitTableUpdateByObjectProvider<T> SplitTable(); SplitTableUpdateByObjectProvider<T> SplitTable();
IUpdateable<T> EnableQueryFilter();
} }
} }

Loading…
Cancel
Save