Esempio n. 1
0
        public static IQueryable <T> Sort <T>(this IQueryable <T> query, SortDefinition sortDefinition)
        {
            if (sortDefinition == null || String.IsNullOrEmpty(sortDefinition.SortBy))
            {
                return(query);
            }

            string sortBy = sortDefinition.SortBy;
            var    prop   = PropertyMetadataCache <T> .GetPropertyMetadata(sortDefinition.SortBy);

            if (!String.IsNullOrEmpty(prop.SortMember))
            {
                sortBy += "." + prop.SortMember;
            }

            return(query.OrderBy(sortBy + " " + (sortDefinition.Descending ? "desc" : "asc")));
        }
Esempio n. 2
0
        public static IQueryable <T> Filter <T>(this IQueryable <T> query, List <FilterDefinition> filterDefinitions)
        {
            if (filterDefinitions.IsNullOrEmpty())
            {
                return(query);
            }

            var result = query;

            foreach (var filterDefinition in filterDefinitions)
            {
                string filterBy = filterDefinition.Property;
                var    prop     = PropertyMetadataCache <T> .GetPropertyMetadata(filterDefinition.Property);

                if (!String.IsNullOrEmpty(prop.FilterMember))
                {
                    filterBy += "." + prop.FilterMember;
                }

                result = result.Where(filterBy + " = " + filterDefinition.Value);
            }

            return(result);
        }