Ejemplo n.º 1
0
            private static Expression GetThenBy(
                Expression queryExpression,
                OrderingField field)
            {
                string methodName = field.IsDescending ? nameof(Queryable.ThenByDescending) : nameof(Queryable.ThenBy);

                return(Expression.Call(
                           typeof(Queryable),
                           methodName,
                           new System.Type[] { typeof(TDbObject), field.Type },
                           queryExpression,
                           Expression.Lambda(ParameterReplacer.RepalceParameter(field.Expression), DbItem)));
            }
            public static Expression BuildAutoFilter(
                Expression mappingExpression,
                OrderingFields orderingFields,
                TOrder after)
            {
                var filters = new List <FilterValue>(capacity: orderingFields.Fields.Count);

                foreach (OrderingField field in orderingFields.Fields)
                {
                    var value = orderingFields.IsDirect ? after : GetValue(after, field);

                    filters.Add(new FilterValue
                    {
                        Expression = field.Expression,
                        Value      = Expression.Constant(value),
                        IsLower    = field.IsDescending,
                    });
                }

                Expression filter = null;

                for (var current = 0; current < filters.Count; current++)
                {
                    FilterValue currentValue  = filters[current];
                    Expression  currentFilter = null;

                    for (var prev = 0; prev < current; prev++)
                    {
                        FilterValue prevValue = filters[prev];

                        Expression equal = Expression.Equal(prevValue.Expression, prevValue.Value);
                        currentFilter = currentFilter != null?Expression.AndAlso(currentFilter, equal) : equal;
                    }

                    Expression compare = GreateCompareExpression(currentValue);
                    currentFilter = currentFilter != null?Expression.AndAlso(currentFilter, compare) : compare;

                    filter = filter != null?Expression.OrElse(filter, currentFilter) : currentFilter;
                }

                return(ParameterReplacer.RepalceParameter(filter));
            }