public IEnumerable <TEntity> GetAll(int skip, int take, Expression <Func <TEntity, bool> > filter, Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy, string includeProperties)
        {
            try
            {
                var result = RetryCodeKit.Do(() =>
                {
                    try
                    {
                        IQueryable <TEntity> query = DbSet;

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

                        query = includeProperties
                                .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                .Aggregate(query, (current, includeProperty) => current.Include(includeProperty));


                        return(orderBy?.Invoke(query).Skip(skip).Take(take).ToList() ?? query.OrderBy(e => e.Id).Skip(skip).Take(take).ToList());
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }, new TimeSpan(0, 0, 0, 30));

                return(result);
            }
            catch (Exception ex)
            {
                throw ExceptionHelpers.ThrowException(ex, true, "Fault in Repository");
            }
        }
        public IEnumerable <TEntity> GetAll(string includeProperties)
        {
            try
            {
                var result = RetryCodeKit.Do(() =>
                {
                    try
                    {
                        IQueryable <TEntity> query = DbSet;

                        if (!string.IsNullOrEmpty(includeProperties))
                        {
                            query = includeProperties
                                    .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
                        }

                        var results = query.ToList();

                        return(results);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }, new TimeSpan(0, 0, 0, 30));

                return(result);
            }
            catch (Exception ex)
            {
                throw ExceptionHelpers.ThrowException(ex, true, "Fault in Repository");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="orderBy"></param>
        /// <param name="fetchLimit"></param>
        /// <param name="includeProperties"></param>
        /// <returns></returns>
        public IEnumerable <TEntity> GetAll(Expression <Func <TEntity, bool> > filter,
                                            Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy,
                                            int fetchLimit,
                                            string includeProperties)
        {
            try
            {
                var result = RetryCodeKit.Do(() =>
                {
                    //try
                    //{
                    IQueryable <TEntity> query = DbSet;

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

                    if (!string.IsNullOrEmpty(includeProperties))
                    {
                        query = includeProperties
                                .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                .Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
                    }

                    if (fetchLimit > 0)
                    {
                        var resultsWithLimit = (orderBy?.Invoke(query).ToList() ?? query.ToList()).Take(fetchLimit);
                        return(resultsWithLimit);
                    }

                    var results = orderBy?.Invoke(query).ToList() ?? query.ToList();
                    return(results);
                    //}
                    //catch (Exception ex)
                    //{
                    //    throw;
                    //}
                }, new TimeSpan(0, 0, 0, 30));

                return(result);
            }
            catch (Exception ex)
            {
                throw ExceptionHelpers.ThrowException(ex, true, "Fault in Repository");
            }
        }
示例#4
0
        public IEnumerable <TEntity> GetList(
            Expression <Func <TEntity, bool> > filter = null,
            Func <IQueryable <TEntity>, IIncludableQueryable <TEntity, object> > include = null,
            Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy            = null,
            int fetchLimit = 0, bool disableTracking = true)
        {
            try
            {
                var result = RetryCodeKit.Do(() =>
                {
                    IQueryable <TEntity> query = DbSet;

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

                    //if (!string.IsNullOrEmpty(includeProperties))
                    //    query = includeProperties
                    //        .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    //        .Aggregate(query, (current, includeProperty) => current.Include(includeProperty));

                    if (fetchLimit > 0)
                    {
                        var resultsWithLimit = (orderBy?.Invoke(query).ToList() ?? query.ToList()).Take(fetchLimit);
                        return(resultsWithLimit);
                    }

                    var results = orderBy?.Invoke(query).ToList() ?? query.ToList();
                    return(results);
                }, new TimeSpan(0, 0, 0, 10));
                return(result);
            }
            catch (Exception ex)
            {
                throw ExceptionHelpers.ThrowException(ex, true, "Fault in Repository");
            }
        }