mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add Queryable.Filter(Type type)
This commit is contained in:
parent
ac7df08ad5
commit
1a5bcef1fa
@ -193,7 +193,15 @@ namespace SqlSugar
|
|||||||
_Filter(FilterName, isDisabledGobalFilter);
|
_Filter(FilterName, isDisabledGobalFilter);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<T> Filter(Type type)
|
||||||
|
{
|
||||||
|
var whereString= QueryBuilder.GetFilters(type);
|
||||||
|
if (whereString.HasValue())
|
||||||
|
{
|
||||||
|
this.Where(whereString);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction)
|
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction)
|
||||||
{
|
{
|
||||||
this.MapperAction=UtilMethods.IsNullReturnNew(this.MapperAction);
|
this.MapperAction=UtilMethods.IsNullReturnNew(this.MapperAction);
|
||||||
|
@ -273,6 +273,38 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal string GetFilters(Type type)
|
||||||
|
{
|
||||||
|
var result = "";
|
||||||
|
if (this.Context != null)
|
||||||
|
{
|
||||||
|
var db = Context;
|
||||||
|
BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||||
|
var index = 0;
|
||||||
|
if (db.QueryFilter.GeFilterList != null)
|
||||||
|
{
|
||||||
|
foreach (var item in db.QueryFilter.GeFilterList)
|
||||||
|
{
|
||||||
|
PropertyInfo field = item.GetType().GetProperty("exp", flag);
|
||||||
|
if (field != null)
|
||||||
|
{
|
||||||
|
Type ChildType = item.GetType().GetProperty("type", flag).GetValue(item, null) as Type;
|
||||||
|
if (ChildType == type)
|
||||||
|
{
|
||||||
|
var entityInfo = db.EntityMaintenance.GetEntityInfo(ChildType);
|
||||||
|
var exp = field.GetValue(item, null) as Expression;
|
||||||
|
var whereStr = index==0 ? " " : " AND ";
|
||||||
|
index++;
|
||||||
|
result += (whereStr + GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string ToSqlString()
|
public virtual string ToSqlString()
|
||||||
{
|
{
|
||||||
string oldOrderBy = this.OrderByValue;
|
string oldOrderBy = this.OrderByValue;
|
||||||
|
@ -27,6 +27,7 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpression);
|
ISugarQueryable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpression);
|
||||||
ISugarQueryable<T, T2> RightJoin<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> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||||
|
ISugarQueryable<T> Filter(Type type);
|
||||||
ISugarQueryable<T> Mapper(Action<T> mapperAction);
|
ISugarQueryable<T> Mapper(Action<T> mapperAction);
|
||||||
ISugarQueryable<T> Mapper<AType, BType, MappingType>(Expression<Func<MappingType, ManyToMany>> expression);
|
ISugarQueryable<T> Mapper<AType, BType, MappingType>(Expression<Func<MappingType, ManyToMany>> expression);
|
||||||
ISugarQueryable<T> Mapper(Action<T, MapperCache<T>> mapperAction);
|
ISugarQueryable<T> Mapper(Action<T, MapperCache<T>> mapperAction);
|
||||||
|
Loading…
Reference in New Issue
Block a user