コード例 #1
0
        public static Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > GetThenBy(string orderColumns, GenericDataFormat.SortType orderType)
        {
            // get order by Query
            Type typeQueryable = typeof(IQueryable <TEntity>);
            ParameterExpression argQueryable = Expression.Parameter(typeQueryable);
            var outerExpression = Expression.Lambda(argQueryable, argQueryable);

            string[]            props = orderColumns.Split('.');
            Type                type  = typeof(TEntity);
            ParameterExpression arg   = Expression.Parameter(type);

            Expression expr = arg;

            foreach (string prop in props)
            {
                PropertyInfo pi = type.GetProperty(prop, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                expr = Expression.Property(expr, pi);
                type = pi.PropertyType;
            }
            LambdaExpression lambda     = Expression.Lambda(expr, arg);
            string           methodName = orderType.Equals(GenericDataFormat.SortType.Desc) ? "ThenByDescending" : "ThenBy";

            MethodCallExpression resultExp =
                Expression.Call(typeof(Queryable), methodName, new Type[] { typeof(TEntity), type }, outerExpression.Body, Expression.Quote(lambda));
            var finalLambda = Expression.Lambda(resultExp, argQueryable);

            Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > thenBy = (Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> >)finalLambda.Compile();

            return(thenBy);
        }
コード例 #2
0
        public virtual List <TModel> GetAsDDLst(string includeProperties, string sortByProperty, List <GenericDataFormat.FilterItems> filters = null, GenericDataFormat.SortType sortType = GenericDataFormat.SortType.Asc, bool GetByView = false)
        {
            var sorts = new List <GenericDataFormat.SortItems>();

            sorts.Add(new GenericDataFormat.SortItems()
            {
                Property = sortByProperty, SortType = sortType
            });
            //create request body parameters
            GenericDataFormat requestBody = new GenericDataFormat()
            {
                Includes = new GenericDataFormat.IncludeItems()
                {
                    Properties = includeProperties
                }, Sorts = sorts
            };

            requestBody.Filters = filters;
            if (!GetByView)
            {
                var lst = this.Get(requestBody);
                return(lst);
            }
            else
            {
                var lst = this.GetView <TModel>(requestBody).PageItems;
                return(lst);
            }
        }