1

EFクエリでネストされたJSON応答を取得したいのですが、これを行う方法がわかりません。モデルを次のように宣言しました。

  [Serializable]
    public class StockReturnMethod
    {
        public int WarehouseID { get; set; }
        public int ProductSKUID { get; set; }
        public int LotID { get; set; }
        public string LotName { get; set; }
        public int AreaID { get; set; }
        public string AreaName { get; set; }
        public int BinID { get; set; }
        public string BinName { get; set; }
        public List<AvailibleStock> Stock { get; set; }
    }


  [Serializable]
    public class AvailibleStock
    {
        public int WarehouseID { get; set; }
        public int ProductSKUID { get; set; }
        public string ProductSKUName { get; set; }
        public string WarehouseName { get; set; }
        public string Status { get; set; }
        public int QtyUnassigned { get; set; }
    }

これが私がこれまでに持っている私のEFクエリです。

    {
       return (from WH in SCMENT.Warehouses 
               join WL in SCMENT.WarehouseLots on WH.WarehouseID equals WL.WarehouseID
               join WA in SCMENT.WarehouseAreas on WL.WarehouseLotID equals WA.WarehouseLotID
               join WB in SCMENT.WarehouseBins on WA.WarehouseAreaID equals WB.WarehouseAreaID
               join SLI in SCMENT.StockLineItems on WH.WarehouseID equals SLI.WarehouseID
               join PSKU in SCMENT.ProductSKUs on SLI.ProductSKUID equals PSKU.ProductSKUID
               where SLI.SystemAreaID == 1

               select new StockReturnMethod() 
               {
                WarehouseID = WH.WarehouseID,
                LotID = WL.WarehouseLotID,
                LotName = WL.WarehouseLotName,
                AreaID = WA.WarehouseAreaID,
                AreaName = WA.WarehouseAreaName,
                BinID = WB.WarehouseBinID,
                BinName = WB.WarehouseBinName,
                ProductSKUID = PSKU.ProductSKUID,
                Stock = (Will I create a sub query here?)


               }

    )
4

1 に答える 1

2
public List<AvailibleStock> Stock { get; set; }

これを次のように変更します。

public IList<AvailibleStock> Stock { get; set; }

編集: これは、参照として使用できる私のプロジェクトの 1 つからの作業サンプルです。

public class StatisticsModel
{
    public int Id { get; set; }
    public int ClientId { get; set; }
    public int Opened { get; set; }
    public IEnumerable<LocationsModel> Locations { get; set; }
}


public class LocationModel
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int OpenCount { get; set; }
}


return dbSet.Select(x => new StatisticsModel
{
    Id = x.Id,
    ClientId = x.ClientId,
    Opened = x.OpenCount,
    Locations = x.Locations.Select(z => new LocationsModel{
        Id = z.Id,
        Name = z.Store.Name,
        OpenCount = z.OpenCount
    })
})
于 2013-03-12T08:46:38.703 に答える