0

注文ヘッダーと注文詳細の2つのモデルがあります。

サーバーからのJSON応答は次のようになります。

--OrderHeader 1
  |
   --OrderDetails 1
--OrderHeader 2
  |
   --Order Detail 2

エンティティフレームワークを使用して、ある種のサブクエリを作成し、WebGetを介してこれを返しますか、それとも別のクエリを実行して、結果が取得された後にフォーマットを統合しますか?

これが私のビューモデルです:

 public class OpenOrderHeader
{
    public int CustomerID { get; set; }
    public int OrderID { get; set; }
    public int OrderUniqueNumber { get; set; }
    public int NumberOfProductsOnOrder { get; set; }
    public DateTime OrderDateCreated { get; set; }
    public DateTime OrderDateUpdated { get; set; }
    public string OrderLocalOnline { get; set; }
    public int BranchID { get; set; }
    public string PaymentMethod { get; set; }
    public int OrderStatus { get; set; }
    public string OrderCurrency { get; set; }
    public decimal OrderConversionRate { get; set; }
    public decimal SubTotalInclTax { get; set; }
    public decimal SubTotalExclTax { get; set; }
    public decimal DiscountInclTax { get; set; }
    public decimal DiscountExclTax { get; set; }
    public decimal ShippingInclTax { get; set; }
    public decimal ShippingExclTax { get; set; }
    public decimal PaymentFeeInclTax { get; set; }
    public decimal PaymentFeeExclTax { get; set; }

}

public class OpenOrderProducts
{
    public int OrderID { get; set; }
    public string ProductSKUName { get; set; }
    public int ProductSKUID { get; set; }
    public string ProductSKUStockCode { get; set; }
    public DateTime ProductAddedToOrder { get; set; }
    public int QtyOfProductsOnOrder { get; set; }
    public decimal UnitPriceinclTax { get; set; }
    public decimal UnitPriceExclTax { get; set; }
    public decimal UnitDiscountInclTax { get; set; }
    public decimal UnitDiscountExclTax { get; set; }
    public decimal LineItemTotalIncludingTax { get; set; }
    public decimal LineItemExclTax { get; set; }
    public decimal LineItemShippingCost { get; set; }
}
4

1 に答える 1

1

エンティティにナビゲーションプロパティOrderdetailsを作成するだけです。OrderHeader次に、クエリを実行できます

var data = db.OrderHeaders.Include(h => h.Orderdetails).ToList();

データをJSONにシリアル化します。

あなたが示すクラスには、 ?OpenOrderHeaderのコレクションがあると思います。OpenOrderProducts

public virtual ICollection<OpenOrderProduct> OpenOrderProducts { get; set; }

(ご覧のとおり、クラスの名前はOpenOrderProduct複数形ではなく、で変更します)

于 2013-02-14T08:58:10.463 に答える