コード例 #1
0
        public virtual PagedList <TEntity> GetPaged(ISpecification <TEntity> specification, int pageIndex = 1, int pageSize = 15, SortExpression <TEntity> sortExpression = null)
        {
            if (specification == null)
            {
                specification = new TrueSpec <TEntity>();
            }
            if (sortExpression == null)
            {
                sortExpression = new DefaultSortExpression <TEntity>();
            }
            if (this.OnGet != null)
            {
                OnGet(ref specification);
            }
            if (specification.Lambda != null)
            {
                var count  = this.Entities.Count(specification.Lambda);
                var result = sortExpression.Lambda(this.Entities.Where(specification.Lambda)).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

                return(new PagedList <TEntity>(pageIndex, pageSize, count, result));
            }
            else
            {
                var condition = specification.Sql;
                var dbBuilder = condition.IsSelect ? condition : DBBuilder.Select(_entityDefinition.Value.TableAttribute.TableName).Where(condition);
                return(this.UnitOfWork.ToList <TEntity>(dbBuilder, pageIndex, pageSize, sortExpression.Sql()));
            }
        }
コード例 #2
0
 public virtual IEnumerable <TEntity> GetAll(ISpecification <TEntity> specification = null, SortExpression <TEntity> sortExpression = null)
 {
     if (specification == null)
     {
         specification = new TrueSpec <TEntity>();
     }
     if (this.OnGet != null)
     {
         OnGet(ref specification);
     }
     if (specification.Lambda != null)
     {
         return((sortExpression == null ? this.Entities.Where(specification.Lambda) : sortExpression.Lambda(this.Entities.Where(specification.Lambda))).ToList());
     }
     else
     {
         var condition = specification.Sql;
         var dbBuilder = condition.IsSelect ? condition : DBBuilder.Select(_entityDefinition.Value.TableAttribute.TableName).Where(condition);
         return(this.UnitOfWork.ToList <TEntity>(dbBuilder, sortExpression == null ? null : sortExpression.Sql()));
     }
 }