使用代码添加母版和详细信息 [英] Add Master and Details with code
问题描述
我希望在论坛的其他地方都不会回答这个问题.
I hope this wasn't answered elsewhere in the forums.
假设我正在如何?"一书中与贝丝的项目一起工作.视频中,她有一个OrderHeader表和一个与一对多关系相关的OrderDetails表.我看到如何通过以下方式在代码中添加新的OrderHeader item:
Suppose I'm working with Beth's project from the "How do I?" videos, where she has an OrderHeader table, and an OrderDetails table related with a one to many relationship. I see how one could add a new OrderHeader item in code by:
Dim oHeader as new OrderHeader()
with oHeader
.HeaderDetail1 = something
.HeaderDetail2 = somethingelse
end with
结尾
一个人如何同时添加一个新的OrderHeader,然后向该标头添加一个新的OrderDetail?
How would one add both a new OrderHeader, and then add a new OrderDetail to that header?
此外,如何将刚刚创建的OrderHeader或OrderDetail定位到其他查询目的?
Also, how could one target the just-created OrderHeader or OrderDetail for other querying purposes?
推荐答案
使用与OrderHeader相同的逻辑. 抱歉,这是在C#中:
Use the same logic as you did for the OrderHeader. Sorry this is in C#:
var oHeader = new OrderHeader();
// Set order header properties here.
var headerDetail = new HeaderDetail();
headerDetail.OrderHeader = oHeader;
// Set header detail properties here
// etc.
如果您还希望将新记录包含在某些查询中,则可能要调用SaveChanges.
You'll probably want to call SaveChanges if you also want the new records to be included in some query.
LightSwitch博客上应该有此示例,但在这里您必须深入研究博客/帖子-您可能找不到专门的博客/帖子名称.
There should be examples of this on the LightSwitch blog and here but you'll have to drill into the blog/post a bit - you might not find it specifically the blog/post name.
希望这会有所帮助.
这篇关于使用代码添加母版和详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!