/// <summary> /// 分页 /// </summary> /// <param name="pagerRequest"></param> /// <param name="totalCount"></param> /// <param name="filter"></param> /// <param name="sortOrder"></param> /// <returns></returns> public List <OpcSupplierInfo> GetPagedList(PagerRequest pagerRequest, out int totalCount, SupplierFilter filter, SupplierSortOrder sortOrder) { var query = Filter(filter); var orderBy = OrderBy(sortOrder); var result = Func(c => { int t; var q1 = EFHelper.GetPaged(c, query, out t, pagerRequest.PageIndex, pagerRequest.PageSize, orderBy); var q2 = from b in c.Set <Brand>() join sb in c.Set <Supplier_Brand>() on b.Id equals sb.Brand_Id into temp1 from sb in temp1.DefaultIfEmpty() select new { b, sb.Supplier_Id }; var q = from s in q1 join b in q2 on s.Id equals b.Supplier_Id into temp1 from sb in temp1.DefaultIfEmpty() select new { Et = s, Brand = sb.b }; var list = new Dictionary <int, OpcSupplierInfo>(); var rst = q.ToList(); rst.ForEach(v => { Brand b = null; if (v.Brand != null) { b = Brand.Convert2Brand(v.Brand); } var item = OpcSupplierInfo.Convert2Supplier(v.Et); OpcSupplierInfo s; if (list.TryGetValue(item.Id, out s)) { if (b != null) { var l = s.Brands.ToList(); l.Add(b); s.Brands = l; } } else { if (b != null) { var l = item.Brands.ToList(); l.Add(b); item.Brands = l; } list.Add(item.Id, item); } }); return(new { totalCount = t, Data = list.Values.ToList() }); }); totalCount = result.totalCount; return(result.Data); }
private static Func <IQueryable <OpcSupplierInfo>, IOrderedQueryable <OpcSupplierInfo> > OrderBy(SupplierSortOrder sortOrder) { Func <IQueryable <OpcSupplierInfo>, IOrderedQueryable <OpcSupplierInfo> > orderBy = null; switch (sortOrder) { default: //orderBy = v => v.OrderByDescending(s => s); break; } return(orderBy); }