将Linq SubQuery转换为按查询分组

时间:2014-01-26 19:16:41

标签: c# linq group-by subquery

我有这个问题:

var query = from i in GetStorageShelfCombinedDTO(s)
                    let res = (from r1 in s.Query<RefResourceStorageShelfDTO>()
                               join r2 in s.Query<ResourceDTO>() on r1.ResourceID equals r2.Id
                               where r1.StorageShelfID == i.StorageShelf.Id
                               select r2)
                    select new StorageShelfResourcesCombinedDTO() { StorageShelf = i.StorageShelf, StorageRack = i.StorageRack, Aisle = i.Aisle, Channel = i.Channel, StorageZone = i.StorageZone, StockArea = i.StockArea, Resources = res.ToList() };

        return query;

是否有可能以某种方式编写此查询,我不需要使用group by的子查询,但我找不到方法......

我的调用GetStorageShelfCombinedDTO看起来像这样(如果需要的话):

    public static IQueryable<StorageShelfCombinedDTO> GetStorageShelfCombinedDTO(BLToolKitSessionWrapper<WMSDL> s)
    {
        var query = from i in s.Query<StorageShelfDTO>()
            join r1 in s.Query<StorageRackDTO>() on i.StorageRackID equals r1.Id
            join r2 in s.Query<AisleDTO>() on i.AisleID equals r2.Id
            join r3 in s.Query<ChannelDTO>() on i.ChannelID equals r3.Id
            join r4 in s.Query<StorageZoneDTO>() on i.StorageZoneID equals r4.Id
            //join r5 in s.Query<PlantDTO>() on i.PlantID equals r5.Id
            join r6 in s.Query<StockAreaDTO>() on i.StockAreaID equals r6.Id
            select new StorageShelfCombinedDTO {StorageShelf = i, StorageRack = r1, Aisle = r2, Channel = r3, StorageZone = r4/*, Plant = r5*/, StockArea = r6};

        return query;
    }

0 个答案:

没有答案