예제 #1
0
        public virtual PageData <T> FindAll <S>(int PageIndex, int PageSize, Domain.Specification.ISpecification <T> specification, System.Linq.Expressions.Expression <Func <T, S> > orderByExpression, bool IsDESC, bool?AsNoTracking = true)
        {
            var query = IsDESC
                     ?
                        dbset.Where(specification.SatisfiedBy()).OrderByDescending(orderByExpression)
                     :
                        dbset.Where(specification.SatisfiedBy()).OrderBy(orderByExpression);

            PageData <T> pageData = new PageData <T>();
            int          quyCount = query.Count();

            if (quyCount > 0)
            {
                pageData.TotalCount = quyCount;
                int TotalPages = (int)Math.Ceiling(pageData.TotalCount / (double)PageSize);
                pageData.CurrentPageIndex = PageIndex > TotalPages ? TotalPages : PageIndex;
                if (AsNoTracking == true)
                {
                    pageData.DataList = query.Skip((pageData.CurrentPageIndex - 1) * PageSize).Take(PageSize).AsNoTracking().ToList();
                }
                else
                {
                    pageData.DataList = query.Skip((pageData.CurrentPageIndex - 1) * PageSize).Take(PageSize).ToList();
                }
            }
            return(pageData);
        }
예제 #2
0
 public virtual IEnumerable <T> GetMany(Domain.Specification.ISpecification <T> specification, bool?AsNoTracking = true)
 {
     if (AsNoTracking == true)
     {
         return(dbset.Where(specification.SatisfiedBy()).AsNoTracking().ToList());
     }
     return(dbset.Where(specification.SatisfiedBy()).ToList());
 }
예제 #3
0
 public virtual T GetByCondition(Domain.Specification.ISpecification <T> specification, bool?AsNoTracking = false)
 {
     if (AsNoTracking == false)
     {
         return(dbset.Where(specification.SatisfiedBy()).FirstOrDefault <T>());
     }
     else
     {
         return(dbset.Where(specification.SatisfiedBy()).AsNoTracking().FirstOrDefault <T>());
     }
 }
예제 #4
0
        public virtual IEnumerable <T> GetListByTopN <S>(int TopN, Domain.Specification.ISpecification <T> specification, System.Linq.Expressions.Expression <Func <T, S> > orderByExpression, bool IsDESC, bool?AsNoTracking = true)
        {
            var query = IsDESC
                 ?
                        dbset.Where(specification.SatisfiedBy()).OrderByDescending(orderByExpression).Take(TopN)
                 :
                        dbset.Where(specification.SatisfiedBy()).OrderBy(orderByExpression).Take(TopN);

            if (AsNoTracking == true)
            {
                return(query.AsNoTracking().ToList());
            }
            return(query.ToList());
        }
예제 #5
0
        public virtual void Remove(Domain.Specification.ISpecification <T> specification)
        {
            IEnumerable <T> objects = dbset.Where <T>(specification.SatisfiedBy()).AsEnumerable();

            foreach (T obj in objects)
            {
                dbset.Remove(obj);
            }
        }
예제 #6
0
 public virtual IEnumerable <T> AllMatching(Domain.Specification.ISpecification <T> specification)
 {
     return(GetSet().Where(specification.SatisfiedBy()));
 }
예제 #7
0
 public int GetCount(Domain.Specification.ISpecification <T> specification)
 {
     return(dbset.Where(specification.SatisfiedBy()).Count());
 }
예제 #8
0
 public virtual bool Exists(Domain.Specification.ISpecification <T> specification)
 {
     return(dbset.Any(specification.SatisfiedBy()));
 }