Ejemplo n.º 1
0
        protected string GetFiltering(FilterObjectWrapper filter)
        {
            var finalExpression = string.Empty;

            foreach (var filterObject in filter.FilterObjects)
            {
                filterObject.Field1 = MapFieldfromViewModeltoEntity(filterObject.Field1);
                filterObject.Field2 = MapFieldfromViewModeltoEntity(filterObject.Field2);

                if (finalExpression.Length > 0)
                {
                    finalExpression += " " + filter.LogicToken + " ";
                }

                if (filterObject.IsConjugate)
                {
                    var expression1 = filterObject.GetExpression1 <TEntity>();
                    var expression2 = filterObject.GetExpression2 <TEntity>();
                    var combined    = $"({expression1} {filterObject.LogicToken} {expression2})";
                    finalExpression += combined;
                }
                else
                {
                    var expression = filterObject.GetExpression1 <TEntity>();
                    finalExpression += expression;
                }
            }

            return(finalExpression.Length == 0 ? "true" : finalExpression);
        }
Ejemplo n.º 2
0
        private IQueryable <TEntity> ApplyFiltering(IQueryable <TEntity> query, FilterObjectWrapper filter)
        {
            string filtering = GetFiltering(filter);

            return(filtering != null?query.Where(filtering) : query);
        }