/// <summary> /// 分页查询[使用版本,其他分页未测试] /// </summary> /// <param name="whereExpression">条件表达式</param> /// <param name="intPageIndex">页码(下标0)</param> /// <param name="intPageSize">页大小</param> /// <param name="strOrderByFields">排序字段,如name asc,age desc</param> /// <returns></returns> public async Task <PageModel <TEntity> > QueryPageAsync(Expression <Func <TEntity, bool> > whereExpression, int intPageIndex = 1, int intPageSize = 20, string strOrderByFields = null) { RefAsync <int> totalCount = 0; var list = await Db.Queryable <TEntity>() .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) .WhereIF(whereExpression != null, whereExpression) .ToPageListAsync(intPageIndex, intPageSize, totalCount); var pageCount = Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal()).ObjToInt(); return(new PageModel <TEntity> { DataCount = totalCount, PageCount = pageCount, Page = intPageIndex, PageSize = intPageSize, Data = list }); }
public async Task <PageModel <TEntity> > QueryPage(Expression <Func <TEntity, bool> > whereExpression, int pageIndex = 0, int pageSize = 20, string orderFields = null) { RefAsync <int> totalCount = 0; var data = await Db.Queryable <TEntity>() .OrderByIF(!string.IsNullOrWhiteSpace(orderFields), orderFields) .WhereIF(whereExpression != null, whereExpression) .ToPageListAsync(pageIndex, pageSize, totalCount); int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / pageSize.ObjToDecimal())) .ObjToInt(); return(new PageModel <TEntity>() { DataCount = totalCount, PageCount = pageCount, Page = pageIndex, PageSize = pageSize, Data = data }); }
/// <summary> ///查询-多表查询 /// </summary> /// <typeparam name="T">实体1</typeparam> /// <typeparam name="T2">实体2</typeparam> /// <typeparam name="TResult">返回对象</typeparam> /// <param name="joinExpression">关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo}</param> /// <param name="selectExpression">返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo}</param> /// <param name="whereLambda">查询表达式 (w1, w2) =>w1.UserNo == "")</param> /// <returns>值</returns> public async Task <PageModel <TResult> > QueryMuchPage <T, T2, TResult>( Expression <Func <T, T2, object[]> > joinExpression, Expression <Func <T, T2, TResult> > selectExpression, Expression <Func <T, T2, bool> > whereLambda = null, int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null) where T : class, new() { RefAsync <int> totalCount = 0; var list = await _db.Queryable(joinExpression) .WhereIF(whereLambda != null, whereLambda) .OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds) .Select(selectExpression) .ToPageListAsync(intPageIndex, intPageSize, totalCount); int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt(); return(new PageModel <TResult>() { dataCount = totalCount, pageCount = pageCount, page = intPageIndex, PageSize = intPageSize, data = list }); }
public async Task <PageModel <TDetail> > QueryTDetailPage <TDetail>(List <Expression <Func <TDetail, bool> > > whereExpressions, int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null) where TDetail : class { RefAsync <int> totalCount = 0; var queryable = _db.Queryable <TDetail>(); queryable = queryable.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds); foreach (var whereExpression in whereExpressions) { queryable = queryable.WhereIF(whereExpression != null, whereExpression); } var list = await queryable.ToPageListAsync(intPageIndex, intPageSize, totalCount); int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt(); return(new PageModel <TDetail>() { dataCount = totalCount, pageCount = pageCount, pageIndex = intPageIndex, pageSize = intPageSize, data = list }); }
public async Task <PageModel <TResult> > QueryMuch <T, T2, T3, T4, T5, T6, T7, T8, T9, TResult>( Expression <Func <T, T2, T3, T4, T5, T6, T7, T8, T9, object[]> > joinExpression, int intPageIndex = 0, int intPageSize = 20, Expression <Func <T, T2, T3, T4, T5, T6, T7, T8, T9, bool> > whereLambda = null) where T : class, new() { RefAsync <int> totalCount = 0; var list = await db.Queryable(joinExpression).Select <TResult>() .Select <TResult>() .ToPageListAsync(intPageIndex, intPageSize, totalCount); if (whereLambda != null) { list = await db.Queryable(joinExpression).Where(whereLambda).Select <TResult>() .Select <TResult>() .ToPageListAsync(intPageIndex, intPageSize, totalCount); } int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt(); return(new PageModel <TResult>() { dataCount = totalCount, pageCount = pageCount, page = intPageIndex, PageSize = intPageSize, data = list }); }
public async Task <PageModel <blogarticle> > QueryMuchTable(Expression <Func <blogarticle, bool> > whereExpression, int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null) { RefAsync <int> totalCount = 0; int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt(); var list = await Db.Queryable <blogarticle>() .Mapper((it, cache) => { var allTags = cache.GetListByPrimaryKeys <blogarticle_tags>(v => v.Id); it.Tags = allTags.Where(v => v.bBlogID == it.Id).ToList(); var allPrefers = cache.GetListByPrimaryKeys <blogarticle_prefers>(v => v.Id); it.Prefers = allPrefers.Where(v => v.pBlogID == it.Id).Take(5).ToList(); var author = cache.GetListByPrimaryKeys <sysUserInfo>(v => v.bsubmitter); it.Author = author.FirstOrDefault(v => v.uID == it.bsubmitter); }) .Where(whereExpression) .OrderByIF(true, strOrderByFileds) .ToPageListAsync(intPageIndex, intPageSize, totalCount); return(new PageModel <blogarticle>() { dataCount = totalCount, pageCount = pageCount, page = intPageIndex, PageSize = intPageSize, data = list }); }
/// <summary> /// 两表联合查询-分页-分组 /// </summary> /// <typeparam name="T">实体1</typeparam> /// <typeparam name="T2">实体1</typeparam> /// <typeparam name="TResult">返回对象</typeparam> /// <param name="joinExpression">关联表达式</param> /// <param name="selectExpression">返回表达式</param> /// <param name="whereExpression">查询表达式</param> /// <param name="intPageIndex">页码</param> /// <param name="intPageSize">页大小</param> /// <param name="strOrderByFileds">排序字段</param> /// <returns></returns> public async Task <PagedModel <TResult> > QueryTabsPage <T, T2, TResult>( Expression <Func <T, T2, object[]> > joinExpression, Expression <Func <T, T2, TResult> > selectExpression, Expression <Func <TResult, bool> > whereExpression, Expression <Func <T, object> > groupExpression, int intPageIndex = 1, int intPageSize = 20, string strOrderByFileds = null) { RefAsync <int> totalCount = 0; var list = await Db.Queryable <T, T2>(joinExpression).GroupBy(groupExpression) .Select(selectExpression) .OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds) .WhereIF(whereExpression != null, whereExpression) .ToPageListAsync(intPageIndex, intPageSize, totalCount); int pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intPageSize.ObjToDecimal())).ObjToInt(); return(new PagedModel <TResult>() { TotalCount = totalCount, TotalPages = pageCount, PageIndex = intPageIndex, PageSize = intPageSize, PageData = list }); }