Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定实体
        /// <para>注意:当需要对查询结果进行排序时,应先排序再进行分页</para>
        /// </summary>
        /// <param name="specification">规约</param>
        /// <param name="tracking">是否追踪,追踪数据可进行修改、删除,不追踪提升查询性能</param>
        /// <returns>返回满足条件的实体</returns>
        public virtual IQueryable <TEntity> Get(IANSHSpecification <TEntity> specification, bool tracking = false)
        {
            IQueryable <TEntity> iqueryable = tracking ? DbEntity.AsTracking() : DbEntity.AsNoTracking();

            iqueryable = iqueryable.SetSpecification(specification);
            return(iqueryable);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public virtual async Task <TAggregateRoot> GetOneAsync(IANSHSpecification <TAggregateRoot> specification = null) => await Repository.GetOneAsync(specification);
Ejemplo n.º 3
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public virtual TAggregateRoot GetOne(IANSHSpecification <TAggregateRoot> specification = null) => Repository.GetOne(specification);
Ejemplo n.º 4
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <param name="datacount">满足指定条件数据总条数</param>
 /// <param name="pagecount">满足指定条件数据可分页总数</param>
 /// <param name="hasnext">是否还有下一页</param>
 /// <param name="page">页数</param>
 /// <param name="pagesize">每页数据条数</param>
 /// <returns>返回满足条件的实体</returns>
 public virtual List <TAggregateRoot> GetList(out int datacount, out int pagecount, out bool hasnext, int page = 1, int pagesize = 20, IANSHSpecification <TAggregateRoot> specification = null) => Repository.GetList(out datacount, out pagecount, out hasnext, page, pagesize, specification);
Ejemplo n.º 5
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public virtual List <TAggregateRoot> GetList(IANSHSpecification <TAggregateRoot> specification = null) => Repository.GetListAsync(specification).Result;
Ejemplo n.º 6
0
 /// <summary>
 /// 获取指定实体数量
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体数量</returns>
 public virtual async Task <int> CountAsync(IANSHSpecification <TAggregateRoot> specification = null) => await Repository.CountAsync(specification);
Ejemplo n.º 7
0
 /// <summary>
 /// 获取指定实体数量
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体数量</returns>
 public virtual int Count(IANSHSpecification <TAggregateRoot> specification = null) => Repository.Count(specification);
Ejemplo n.º 8
0
    /// <summary>
    /// 设置规约
    /// </summary>
    /// <typeparam name="TEntity">实体模型</typeparam>
    /// <param name="source">来源</param>
    /// <param name="specification">规约</param>
    public static IQueryable <TEntity> SetSpecification <TEntity> (this IQueryable <TEntity> source, IANSHSpecification <TEntity> specification) where TEntity : class, IDBEntity
    {
        var Criteria = specification.GetCriteria();

        if (Criteria != null)
        {
            source = source.Where(Criteria);
        }
        var InCludes = specification.GetInClude();

        source = InCludes?.Aggregate(source,
                                     (current, include) => current.Include(include));

        var ThenInCludes = specification.GetThenInClude();

        source = ThenInCludes?.Aggregate(source,
                                         (current, include) => current.Include(include));

        var OrderBy = specification.GetOrderBy();

        source = OrderBy?.Aggregate(source, (current, include) => include.Value == ANSHSpecificationOrderBy.ASC? current.OrderBy(include.Key) : current.OrderByDescending(include.Key));

        return(source);
    }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <param name="datacount">满足指定条件数据总条数</param>
 /// <param name="pagecount">满足指定条件数据可分页总数</param>
 /// <param name="hasnext">是否还有下一页</param>
 /// <param name="page">页数</param>
 /// <param name="pagesize">每页数据条数</param>
 /// <returns>返回满足条件的实体</returns>
 public List <TAggregateRoot> GetList(out int datacount, out int pagecount, out bool hasnext, int page = 1, int pagesize = 20, IANSHSpecification <TAggregateRoot> specification = null) => Work.Register <TAggregateRootContxt> ().Get(specification).ToPage(out datacount, out pagecount, out hasnext, page, pagesize).ToListAsync().Result;
Ejemplo n.º 10
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public List <TAggregateRoot> GetList(IANSHSpecification <TAggregateRoot> specification = null) => GetListAsync(specification).Result;
Ejemplo n.º 11
0
 /// <summary>
 /// 获取指定实体数量
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体数量</returns>
 public async Task <int> CountAsync(IANSHSpecification <TAggregateRoot> specification = null) => await Work.Register <TAggregateRootContxt> ().Get(specification).CountAsync();
Ejemplo n.º 12
0
 /// <summary>
 /// 获取指定实体数量
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体数量</returns>
 public int Count(IANSHSpecification <TAggregateRoot> specification = null) => CountAsync(specification).Result;
Ejemplo n.º 13
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public async Task <TAggregateRoot> GetOneAsync(IANSHSpecification <TAggregateRoot> specification = null) => await Work.Register <TAggregateRootContxt> ().Get(specification).FirstOrDefaultAsync();
Ejemplo n.º 14
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public TAggregateRoot GetOne(IANSHSpecification <TAggregateRoot> specification = null) => GetOneAsync(specification).Result;
Ejemplo n.º 15
0
 /// <summary>
 /// 获取指定实体
 /// </summary>
 /// <param name="specification">规约</param>
 /// <returns>返回满足条件的实体</returns>
 public async Task <List <TAggregateRoot> > GetListAsync(IANSHSpecification <TAggregateRoot> specification = null) => await Work.Register <TAggregateRootContxt> ().Get(specification).ToListAsync();