Пример #1
0
        public virtual IEnumerable <T> Get <T>(Expression <Func <T, bool> > filter  = null, Func <IQueryable <T>, IOrderedQueryable <T> > orderBy = null,
                                               IEnumerable <string> relatedEntities = null, int?pageIndex = null, int?pageSize = null) where T : class
        {
            try
            {
                IQueryable <T> query = Context.Set <T>();

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

                if (relatedEntities != null)
                {
                    foreach (var item in relatedEntities)
                    {
                        query = query.Include(item);
                    }
                }

                if (orderBy != null)
                {
                    query = orderBy(query);
                }

                if (pageIndex.HasValue && pageSize.HasValue)
                {
                    query = query.Skip(pageIndex.Value * pageSize.Value).Take(pageSize.Value);
                }
                return(query.ToList());
            }
            catch (Exception exception)
            {
                // EFExceptionHelper.HandleException(exception);
                throw;
            }
        }
Пример #2
0
 /// <summary>
 /// Public Constructor,initializes privately declared local variables.
 /// </summary>
 /// <param name="context"></param>
 public GenericRepository(HRMSEntities context)
 {
     this.Context = context;
     this.DbSet   = context.Set <TEntity>();
 }