Esempio n. 1
0
        /// <summary>
        /// Gets all items.
        /// </summary>
        /// <param name="orderBy">The sort expression</param>
        /// <param name="navigationProperties">The navigation properties.</param>
        /// <returns>All items</returns>
        public IList <T2> GetAll(OrderByParameters <T2, object> orderBy, params Expression <Func <T2, object> >[] navigationProperties)
        {
            List <T2> list;

            using (var context = GetContextInstance())
            {
                IQueryable <T2> query = context.Set <T2>();

                foreach (var navigationProperty in navigationProperties)
                {
                    query = query.Include <T2, object>(navigationProperty);
                }

                query = query.AsNoTracking();
                query = query.ApplyOrderByParameters(orderBy);

                if (SkipResults > 0)
                {
                    query = query.Skip(SkipResults);
                }

                if (MaxResults > 0)
                {
                    query = query.Take(MaxResults);
                }

                list = query.ToList <T2>();
            }

            ResetProperties();

            return(list);
        }
        /// <summary>
        /// Gets all items.
        /// </summary>
        /// <param name="orderBy">The sort expression</param>
        /// <param name="navigationProperties">The navigation properties.</param>
        /// <returns>All items</returns>
        public IList <TEntity> GetAll(
            OrderByParameters <TEntity, object> orderBy,
            params Expression <Func <TEntity, object> >[] navigationProperties)
        {
            Expression <Func <TEntity, TEntity> > projection = x => x;

            return(GetAll(projection, orderBy, navigationProperties));
        }
Esempio n. 3
0
 void OnPageLoadComplete(object sender, EventArgs e)
 {
     SelectParameters.UpdateValues(Context, this);
     WhereParameters.UpdateValues(Context, this);
     GroupByParameters.UpdateValues(Context, this);
     OrderByParameters.UpdateValues(Context, this);
     OrderGroupsByParameters.UpdateValues(Context, this);
 }
        /// <summary>
        /// Gets results with specified filter.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="navigationProperties">The navigation properties.</param>
        /// <returns>
        /// Matching items
        /// </returns>
        public IList <TEntity> GetFiltered(
            Expression <Func <TEntity, bool> > predicate,
            OrderByParameters <TEntity, object> orderBy,
            params Expression <Func <TEntity, object> >[] navigationProperties)
        {
            Expression <Func <TEntity, TEntity> > projection = x => x;

            return(GetFiltered(predicate, projection, orderBy, navigationProperties));
        }
Esempio n. 5
0
        protected QueryContext CreateQueryContext(DataSourceSelectArguments arguments)
        {
            IDictionary <string, object> whereParameters         = WhereParameters.ToDictionary(_context, _owner);
            IOrderedDictionary           orderByParameters       = OrderByParameters.GetValues(_context, _owner).ToCaseInsensitiveDictionary();
            IDictionary <string, object> orderGroupsByParameters = OrderGroupsByParameters.ToDictionary(_context, _owner);
            IDictionary <string, object> selectNewParameters     = SelectNewParameters.ToDictionary(_context, _owner);
            IDictionary <string, object> groupByParameters       = GroupByParameters.ToDictionary(_context, _owner);

            return(new QueryContext(
                       whereParameters,
                       orderGroupsByParameters,
                       orderByParameters,
                       groupByParameters,
                       selectNewParameters,
                       arguments));
        }
        /// <summary>
        /// Gets results with specified filter.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="predicate">The predicate.</param>
        /// <param name="projection">The projection.</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="navigationProperties">The navigation properties.</param>
        /// <returns>
        /// Matching items
        /// </returns>
        public IList <TResult> GetFiltered <TResult>(
            Expression <Func <TEntity, bool> > predicate,
            Expression <Func <TEntity, TResult> > projection,
            OrderByParameters <TEntity, object> orderBy,
            params Expression <Func <TEntity, object> >[] navigationProperties)
        {
            IList <TResult> list;

            using (var context = GetContextInstance())
            {
                IQueryable <TEntity> query = context.Set <TEntity>();

                foreach (var navigationProperty in navigationProperties)
                {
                    query = query.Include <TEntity, object>(navigationProperty);
                }

                query = query.Where(predicate).AsQueryable();
                query = query.AsNoTracking();
                query = query.ApplyOrderByParameters(orderBy);

                if (SkipResults > 0)
                {
                    query = query.Skip(SkipResults);
                }

                if (MaxResults > 0)
                {
                    query = query.Take(MaxResults);
                }

                list = query.Select(projection).ToList();
            }

            ResetProperties();

            return(list);
        }
        /// <summary>
        /// Applies the order by parameters to a LINQ collection.
        /// </summary>
        /// <typeparam name="T">Type of the collection being ordered</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="orderBy">The order by.</param>
        /// <returns>Enumerable collection in the requested order</returns>
        public static IQueryable <T> ApplyOrderByParameters <T>(this IQueryable <T> query, OrderByParameters <T, object> orderBy)
        {
            if (orderBy == null)
            {
                return(query);
            }

            if (orderBy.Direction == Constants.Enums.OrderByDirections.Descending)
            {
                return(query.OrderByDescending(orderBy.SortExpression).AsQueryable());
            }
            else
            {
                return(query.OrderBy(orderBy.SortExpression).AsQueryable());
            }
        }