首页 新闻 搜索 专区 学院

关于 C# GroupBy使用AsQueryable的报错

0
悬赏园豆:40 [已关闭问题] 关闭于 2021-07-27 09:32

下面为代码:


            var commodity = _appDbContext.ArchivesCCommodity.Where(lambda)
              .GroupJoin(_appDbContext.ArchivesCCommoditySpecification, a => a.Code, b => b.Commodity, (a, b) => new { a, b })
              .SelectMany(a => a.b.DefaultIfEmpty(), (a, b) => new { a.a, b })
              .GroupJoin(_appDbContext.ArchivesCSpecificationDetail, a => a.a.a.b.SpecificationDetail, d => d.Code, (a, d) => new { a, d })
              .SelectMany(a => a.d.DefaultIfEmpty(), (a, d) => new
              {
                  Commodity = a.a.a.Code,
                  CommodityName = a.a.a.Name,
                  SpecificationDetailName = d.Name,
                  OrderSN = d.OrderSN
              }).AsQueryable().OrderBy(a => a.OrderSN).GroupBy(a => new { a.Commodity, a.CommodityName })
               .Select(a => new
               {
                   Commodity = a.Key.Commodity,
                   CommodityName = a.Key.CommodityName,
                   SpecificationDetailName = string.Join(" - ", a.Select(a => a.SpecificationDetailName)),
                   SpecificationDetailTotal = string.Join(" - ", a.Select(a => a.SpecificationDetailName)) == "" ? 0 : a.Count()
               }); ;


其中这句 .AsQueryable() 会导致报错

.AsQueryable().OrderBy(a => a.OrderSN).GroupBy(a => new { a.Commodity, a.CommodityName })

换成 AsEnumerable() 就好

但是我想这段代码暂时不要发送到数据库,因为后面还要套分页查询等,想在后面再发送,不知该如何处理?

afr751116的主页 afr751116 | 初学一级 | 园豆:122
提问于:2021-07-18 10:02
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册