Browse Source

Update gobal filter

pull/31/head
sunkaixuan 2 years ago
parent
commit
66a8d5f6dc
  1. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs
  2. 6
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 14
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/Entities/SqlFilter.cs
  5. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

1
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs

@ -1556,6 +1556,7 @@ namespace SqlSugar
asyncQueryableBuilder.SubToListParameters= this.Context.Utilities.TranslateCopy(this.QueryBuilder.SubToListParameters);
asyncQueryableBuilder.AppendColumns = this.Context.Utilities.TranslateCopy(this.QueryBuilder.AppendColumns);
asyncQueryableBuilder.AppendValues = this.Context.Utilities.TranslateCopy(this.QueryBuilder.AppendValues);
asyncQueryableBuilder.RemoveFilters = this.QueryBuilder.RemoveFilters?.ToArray();
}
protected int SetCacheTime(int cacheDurationInSeconds)
{

6
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -266,6 +266,12 @@ namespace SqlSugar
this.Filter(null, true);
return this;
}
public ISugarQueryable<T> ClearFilter(params Type[] types)
{
this.QueryBuilder.RemoveFilters = types;
this.Filter(null, true);
return this;
}
public ISugarQueryable<T> Filter(Type type)
{
this.Context.InitMappingInfo(type);

14
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -34,6 +34,7 @@ namespace SqlSugar
#endregion
#region Splicing basic
public Type[] RemoveFilters { get; set; }
public Dictionary<string, object> SubToListParameters { get; set; }
internal List<QueryableAppendColumn> AppendColumns { get; set; }
internal List<List<QueryableAppendColumn>> AppendValues { get; set; }
@ -297,7 +298,7 @@ namespace SqlSugar
if (this.Context != null)
{
var db = Context;
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic| BindingFlags.Public;
var index = 0;
if (db.QueryFilter.GeFilterList != null)
{
@ -306,7 +307,7 @@ namespace SqlSugar
PropertyInfo field = item.GetType().GetProperty("exp", flag);
if (field != null)
{
Type ChildType = item.GetType().GetProperty("type", flag).GetValue(item, null) as Type;
Type ChildType = item.type;
var isInterface = ChildType.IsInterface && type.GetInterfaces().Any(it => it == ChildType);
if (ChildType == type|| isInterface)
{
@ -366,7 +367,10 @@ namespace SqlSugar
if (!IsDisabledGobalFilter && this.Context.QueryFilter.GeFilterList.HasValue())
{
var gobalFilterList = this.Context.QueryFilter.GeFilterList.Where(it => it.FilterName.IsNullOrEmpty()).ToList();
if (this.RemoveFilters != null && this.RemoveFilters.Length > 0)
{
gobalFilterList = gobalFilterList.Where(it => !this.RemoveFilters.Contains(it.type)).ToList();
}
foreach (var item in gobalFilterList)
{
if (item.GetType().Name.StartsWith("TableFilterItem"))
@ -389,10 +393,10 @@ namespace SqlSugar
private void AppendTableFilter(SqlFilterItem item)
{
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic |BindingFlags.Public;
Type type = item.GetType();
PropertyInfo field = type.GetProperty("exp", flag);
Type ChildType = type.GetProperty("type", flag).GetValue(item, null) as Type;
Type ChildType = item.type;
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(ChildType);
var exp = field.GetValue(item, null) as Expression;
var isMain = ChildType == this.EntityType||(ChildType.IsInterface&& this.EntityType.GetInterfaces().Any(it => it == ChildType));

2
Src/Asp.NetCore2/SqlSugar/Entities/SqlFilter.cs

@ -17,6 +17,7 @@ namespace SqlSugar
/// Is it a multiple table query?
/// </summary>
public bool IsJoinQuery { get; set; }
internal Type type { get; set; }
}
public class TableFilterItem<T>: SqlFilterItem
@ -26,7 +27,6 @@ namespace SqlSugar
}
private Expression exp { get; set; }
private Type type { get; set; }
public TableFilterItem(Expression<Func<T,bool>> expression,bool isJoinOn=false)
{
exp = expression;

1
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -33,6 +33,7 @@ namespace SqlSugar
ISugarQueryable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpression);
ISugarQueryable<T, T2> RightJoin<T2>(Expression<Func<T, T2, bool>> joinExpression);
ISugarQueryable<T> Filter(string FilterName, bool isDisabledGobalFilter = false);
ISugarQueryable<T> ClearFilter(params Type[] types);
ISugarQueryable<T> ClearFilter();
ISugarQueryable<T> Filter(Type type);
ISugarQueryable<T> Mapper(Action<T> mapperAction);

Loading…
Cancel
Save