Esempio n. 1
0
        /// <summary>
        ///     Gets the many objects including the properties sent.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <param name="orderBy">The order by clause.</param>
        /// <param name="includePath">The include properties.</param>
        /// <param name="asNoTracking">if set to <c>true</c> [as no tracking].</param>
        /// <param name="orderByAscending"> if set true - order by ASCENDING otherwise order by DESCENDING. </param>
        /// <returns></returns>
        protected virtual IEnumerable <T> GetManyIncluding(
            Expression <Func <T, bool> > where,
            Expression <Func <T, object> > orderBy,
            EntityPath <T> includePath,
            bool asNoTracking     = false,
            bool orderByAscending = true)
        {
            IQueryable <T> query = Context.Set <T>();

            if (includePath != null)
            {
                query = includePath.Apply(query);
            }

            var rs = asNoTracking
                ? query.AsNoTracking().Where(where)
                : query.Where(where);

            if (orderBy != null)
            {
                rs = orderByAscending
                    ? rs.OrderBy(orderBy)
                    : rs.OrderByDescending(orderBy);
            }

            // Return the value.
            return(rs.ToList());
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets the entity according the where, including the properties received.
        /// </summary>
        /// <param name="where"> Expression for the where. </param>
        /// <param name="asNoTracking">If set to <c>true</c> [as no tracking].</param>
        /// <param name="includePath"> The include properties. </param>
        /// <returns> </returns>
        protected virtual T GetIncluding(
            Expression <Func <T, bool> > where, bool asNoTracking, EntityPath <T> includePath)
        {
            IQueryable <T> query = Context.Set <T>();

            query = includePath.Apply(query);

            return(asNoTracking
                ? query.AsNoTracking().Where(where).ToList().FirstOrDefault()
                : query.Where(where).ToList().FirstOrDefault());
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets a lists of entities paginated according the where.
        /// </summary>
        /// <param name="where"> The where. </param>
        /// <param name="orderBy"> The order by. </param>
        /// <param name="pageIndex"> Index of the page. </param>
        /// <param name="pageSize"> Size of the page. </param>
        /// <param name="totalRecords"> The total records. </param>
        /// <param name="asNoTracking"> if set to <c>true</c> [as no tracking]. </param>
        /// <param name="orderByAscending"> if set true - order by ASCENDING otherwise order by DESCENDING. </param>
        /// <param name="includePath"> The include properties. </param>
        /// <returns> </returns>
        protected virtual IEnumerable <T> GetManyPaginated(
            Expression <Func <T, bool> > where, Expression <Func <T, object> > orderBy, int pageIndex,
            int pageSize,
            out int totalRecords, bool asNoTracking = false, bool orderByAscending = true,
            EntityPath <T> includePath = null)
        {
            var query = Context.Set <T>().AsQueryable();

            totalRecords = query.Where(where).Count();

            if (includePath != null)
            {
                query = includePath.Apply(query);
            }

            var rs = asNoTracking
                ? query.AsNoTracking().Where(where)
                : query.Where(where);

            return(orderByAscending
                ? rs.OrderBy(orderBy).Skip(pageSize * pageIndex).Take(pageSize).ToList()
                : rs.OrderByDescending(orderBy).Skip(pageSize * pageIndex).Take(pageSize).ToList());
        }