实际上如何在 Entity Framework 4 Code-First CTP 5 中执行关系?
我想通过一个简短的示例来了解如何在 Entity Framework 4 Code-First CTP 5 中实际执行关系?
希望有一个此类关系的例子:
* one-to-many
* many-to-many
非常感谢!
I would like to have a short example on how do you actually perform relationships in Entity Framework 4 Code-First CTP 5 ?
Would love an example for these kind of relations :
* one-to-many
* many-to-many
Thanks a lots!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一对一
需要注意的是,它必须是虚拟的
一对多
多对多
注意它需要是ICollection
以下链接可能有帮助,单击并点击
希望这会有所帮助。
编辑
更新为包括一对多。
编辑 #2
已更新,包括可以进行发票 <->评论所要求的产品场景。
注意:这尚未经过测试,但应该会让您朝着正确的方向
使用此功能,您可以遍历发票上的所有项目,然后 foreach 能够显示有关每个项目的发票详细信息以及产品本身的描述。
One to One
Things to note, it has to be virtual
One to Many
Many to Many
note that it needs to be ICollection
Following links maybe helpful, click and click
Hope this helps.
EDIT
Updated to include one to many.
EDIT #2
Updated to include a potential for doing the Invoice <-> Product scenario which was requested by comment.
note: this is untested, but should put you in the right direction
Using this you could then iterate through all the items on the invoice and then foreach be able to show the invoice details about each item as well as a description from the product itself.