public static Expression Clean(Expression expression) { Expression expand = ExpressionCleaner.Clean(expression, MetaEvaluator.PartialEval, false); Expression simplified = OverloadingSimplifier.Simplify(expand); return(simplified); }
protected override Expression VisitConstant(ConstantExpression c) { if (disableQueryFilter) { return(base.VisitConstant(c)); } if (typeof(IQueryable).IsAssignableFrom(c.Type)) { IQueryable query = (IQueryable)c.Value; if (query.IsBase()) { Type queryType = c.Type.GetGenericArguments().SingleEx(); if (filter) { if (typeof(Entity).IsAssignableFrom(queryType)) { LambdaExpression?rawFilter = giFilter.GetInvoker(queryType)(Schema.Current); if (rawFilter != null) { Expression clean = ExpressionCleaner.Clean(rawFilter) !; var cleanFilter = (LambdaExpression)OverloadingSimplifier.Simplify(clean) !; return(Expression.Call(miWhere.MakeGenericMethod(queryType), query.Expression, cleanFilter)); } } else if (queryType.IsInstantiationOf(typeof(MListElement <,>))) { Type entityType = queryType.GetGenericArguments()[0]; LambdaExpression?rawFilter = giFilter.GetInvoker(entityType)(Schema.Current); if (rawFilter != null) { var param = Expression.Parameter(queryType, "mle"); var lambda = Expression.Lambda(Expression.Invoke(rawFilter, Expression.Property(param, "Parent")), param); Expression clean = ExpressionCleaner.Clean(lambda) !; var cleanFilter = (LambdaExpression)OverloadingSimplifier.Simplify(clean) !; return(Expression.Call(miWhere.MakeGenericMethod(queryType), query.Expression, cleanFilter)); } } } return(c); } else { /// <summary> /// Replaces every expression like ConstantExpression{ Type = IQueryable, Value = complexExpr } by complexExpr /// </summary> return(DbQueryProvider.Clean(query.Expression, filter, null) !); } } return(base.VisitConstant(c)); }
public static Expression?Clean(Expression?expression, bool filter, HeavyProfiler.Tracer?log) { Expression?clean = ExpressionCleaner.Clean(expression); log.Switch("OvrLdSmp"); Expression?simplified = OverloadingSimplifier.Simplify(clean); log.Switch("QrFlr"); Expression?filtered = QueryFilterer.Filter(simplified, filter); return(filtered); }