0
我在項目中使用Odata v4 WebApi 2.2,實體框架6和Odata v4代理客戶端(WPF) 。使用Asp.Net WebApi + EF + Odata深度插入數據
考慮下面的代碼:
//Model Class
public class Order
{
public int OrderId {get;set;} //Auto Generated Id
public string OrderDescription {get;set;}
Public virtual IEnumerable<OrderLine> OrderLines;
}
//Model Class
public class OrderLine
{
public int OrderId {get;set;} //Auto Generated Id
public int OrderLineId {get;set;} //Key of the parent entity
public string PartDescription {get;set;}
Public virtual Order Order;
}
//Odata Proxy Client Code
public void insert()
{
Order order new Order;
order.OrderDescription = "Test Desc";
order.Add(new OrderLine{PartDescription = P100}) //OrderId & OrderLineId is null
order.Add(new OrderLine{PartDescription = P101})//OrderId & OrderLineId is null
order.Add(new OrderLine{PartDescription = P101})//OrderId & OrderLineId is null
//When save changes is called OrderId needs to be set to order lines
Context.SaveChanges();
}
我需要從客戶訂單行創建訂單,併發送回數據庫進行保存。問題是這些密鑰是自動生成的數據庫中的類Order
& OrderLine
。
我需要執行深度插入操作,需要按以下順序完成操作。
- 需要先插入訂單。在插入訂單行之前。
- 訂單行的
OrderId
需要設置。 - 需要插入訂單行。
EF或Odata V4是否支持深插? 我該如何做到這一點?