Ejemplo n.º 1
0
        internal IQueryable <TEntity> GetQueryable(
            Expression <Func <TEntity, bool> > filter = null, int pageGo = 0, int pageSize = 0,
            List <string> orderBy = null, bool orderAscendent            = false, params string[] includes)
        {
            IQueryable <TEntity> items = dbContext.Set <TEntity>();

            items.AsNoTracking();

            if (includes != null && includes.Any())
            {
                includes.Where(i => i != null).ToList().ForEach(i => items = items.Include(i));
            }

            if (filter != null)
            {
                items = items.Where(filter);
            }

            if (pageSize > 0)
            {
                if (orderBy != null && orderBy.Any())
                {
                    orderBy.Where(i => i != null).ToList().ForEach(
                        s => items = QueryableUtils.CallOrderBy(items, s, orderAscendent));
                }
                items = items.Take(pageSize);
            }

            return(items);
        }
Ejemplo n.º 2
0
        //public abstract IQueryable<TEntity> GetQueryable<TEntity>(
        //    Expression<Func<TEntity, bool>> filter = null,
        //    int pageGo = 0,
        //    int pageSize = 0,
        //    IEnumerable<string> orderBy = null,
        //    bool orderAscendent = false,
        //    params Expression<Func<TEntity, object>>[] includes)
        //    where TEntity : class;


        /// <summary>
        ///     The get queryable.
        /// </summary>
        /// <param name="includes">
        ///     The includes.
        /// </param>
        /// <param name="cache"></param>
        /// <param name="filter">
        ///     The filter.
        /// </param>
        /// <param name="pageGo">
        ///     The page go.
        /// </param>
        /// <param name="pageSize">
        ///     The page size.
        /// </param>
        /// <param name="orderBy">
        ///     The order by.
        /// </param>
        /// <param name="orderAscendent">
        ///     The order ascendent.
        /// </param>
        /// <typeparam name="TEntity">
        ///     The Entity Type
        /// </typeparam>
        /// <returns>
        ///     The <see cref="IQueryable" />.
        /// </returns>
        public virtual IQueryable<TEntity> GetQueryable<TEntity>(
            bool cache,
            Expression<Func<TEntity, bool>> filter = null,
            int pageGo = 0,
            int pageSize = 0,
            IEnumerable<string> orderBy = null,
            bool orderAscendent = false,
            params Expression<Func<TEntity, object>>[] includes)
            where TEntity : class
        {
            IQueryable<TEntity> items = null;

            if (includes != null && includes.Any())
            {
                var include = string.Empty;
                var first = true;

                foreach (var includeExpression in includes)
                {
                    //items.Include(includeExpression);
                    include = GetPath(includeExpression);
                    if (first)
                    {
                        items = Set<TEntity>().Include(include);
                        first = false;
                    }
                    else
                    {
                        items = items.Include(include);
                    }
                }
            }
            else
            {
                items = Set<TEntity>();
            }

            if (filter != null) items = items.Where(filter);

            if (pageSize > 0)
            {
                var orderByList = orderBy == null ? new List<string>() : orderBy.ToList();

                if (orderByList.Any())
                {
                    foreach (var i in orderByList.Where(o => !string.IsNullOrEmpty(o)))
                        items = QueryableUtils.CallOrderBy(items, i, orderAscendent);

                    items = items.Skip(pageSize * (pageGo - 1));
                }

                items = items.Take(pageSize);
            }

            if (cacheProvider != null && cache)
                return items.Cacheable();
            return items;
            //return this.cacheProvider != null ? items.Cacheable() : items;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     The get queryable.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="filter">
        ///     The filter.
        /// </param>
        /// <param name="pageGo">
        ///     The page go.
        /// </param>
        /// <param name="pageSize">
        ///     The page size.
        /// </param>
        /// <param name="orderBy">
        ///     The order by.
        /// </param>
        /// <param name="orderAscendent">
        ///     The order ascendent.
        /// </param>
        /// <param name="includes">
        ///     The includes.
        /// </param>
        /// <typeparam name="TEntity">
        /// </typeparam>
        /// <returns>
        ///     The <see cref="IQueryable" />.
        /// </returns>
        public virtual IQueryable <TEntity> GetQueryable <TEntity>(
            bool cache,
            Expression <Func <TEntity, bool> > filter = null,
            int pageGo   = 0,
            int pageSize = 0,
            IEnumerable <string> orderBy = null,
            bool orderAscendent          = false,
            params Expression <Func <TEntity, object> >[] includes)
            where TEntity : class
        {
            var query = CurrentSession.Query <TEntity>();

            if (includes != null && includes.Any())
            {
                foreach (var includeExpr in includes)
                {
                    query = query.Fetch(includeExpr);
                }
            }

            if (filter != null)
            {
                query = query.Where(filter);
            }

            if (pageSize > 0)
            {
                if (orderBy != null)
                {
                    var orderBylist = orderBy.ToList();

                    foreach (var i in orderBylist.Where(o => !string.IsNullOrEmpty(o)))
                    {
                        query = QueryableUtils.CallOrderBy(query, i, orderAscendent);
                    }

                    query = query.Skip(pageSize * (pageGo - 1));
                }

                query = query.Take(pageSize);
            }

            if (cache)
            {
                return(query.WithOptions(o => o.SetCacheable(true)));
            }
            else
            {
                return(query);
            }
        }