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); }
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()); }
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>()); } }
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()); }
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); } }
public virtual IEnumerable <T> AllMatching(Domain.Specification.ISpecification <T> specification) { return(GetSet().Where(specification.SatisfiedBy())); }
public int GetCount(Domain.Specification.ISpecification <T> specification) { return(dbset.Where(specification.SatisfiedBy()).Count()); }
public virtual bool Exists(Domain.Specification.ISpecification <T> specification) { return(dbset.Any(specification.SatisfiedBy())); }