linq to sql-当插入一行(以及其他几行fk将指向此行的pk)时,是否足够执行[context].[maintable].insertonsubmit(row),或者是否也需要为其他行调用它?
下面是压缩代码示例(C):
//Forgive the contrived example (off the top of my head) :)
//Main row
Order order = new Order
{
itemId = (int) data["itemNumber"],
address = (string) data["address"]
};
db.Orders.InsertOnSubmit(order); //would be nice to only have to submit here.
//Related rows
OrderPerson orderPerson = new OrderPerson
{
Order = order,
//other things, etc.
orderRoleId = RoleIds.Customer
};
//Q: need to do "db.OrderPerson.InsertOnSubmit(orderPerson);" here?
OrderHistoryEntry historyEntry = new OrderHistoryEntry
{
Order = order,
//other things, etc.
historyTypeId = HistoryIds.Ordered
};
//Q: need to do "db.OrderHistoryEntry.InsertOnSubmit(historyEntry);" here?
db.SubmitChanges();
是否足够:
db.Orders.InsertOnSubmit(order);
或者,是否还需要为相关行(orderPerson和historyEntry)执行insertonSubmit?
最好只在主行运行一次。msdn示例就是这样做的,但它们都具有相反的关系(引用主行中的其他行)。
我很感激你的想法。