Пример #1
0
        public static IEnumerable <TR> MapList <T, TR>(this IEnumerable <T> lst) where T : class where TR : class
        {
            Expression <Func <T, TR> > expression = ExpressionStore.GetExpression <T, TR>();

            if (lst is IQueryable <T> )
            {
                ((IQueryable <T>)lst).Select(expression).ToList();
            }
            return(lst.Select(expression.Compile()).ToList());
        }
        public ListOptions <T> ToModelGetOptions(LoadOptions posted, bool ignoreFilters = false)
        {
            ListOptions <T> opts = new ListOptions <T>();

            opts.Skip       = posted.Skip;
            opts.Showing    = posted.Showing;
            opts.SearchTerm = posted.SearchTerm;
            SortDir dir;

            if (Enum.TryParse(posted.Direction, out dir))
            {
                opts.Direction = dir;
            }

            opts.OrderProperty = posted.OrderProperty;

            if (posted.Filters != null && !ignoreFilters)
            {
                opts.Filters = ToFilterExpressions(posted.PropertyFilters);
            }

            if (!string.IsNullOrEmpty(posted.SearchTerm))
            {
                var ex = ExpressionStore.GetSearchExpression <T>(posted.SearchTerm);
                if (ex != null)
                {
                    opts.AddFilter(ex);
                }
                else if (typeof(T).Implements(typeof(INamed)))
                {
                    Expression <Func <T, bool> > iex = e => ((INamed)e).Name.Contains(posted.SearchTerm);
                    opts.AddFilter(iex);
                }
            }
            return(opts);
        }
Пример #3
0
 public static IEnumerable <TR> MapList <T, TR>(this IQueryable <T> lst) where T : class where TR : class
 {
     return(lst.Select(ExpressionStore.GetExpression <T, TR>()).ToList());
 }