实体数据模型中的外键
我使用实体数据模型,但我有一个问题:如果一个表,例如客户有categoryId(来自表类别的外键),它不会出现在客户实体中??? 那么我怎样才能检索或设置这个值呢?
I use Entity Data Model but I have aproblem: If a table e.g Customers have categoryId(foreign key from table category) it is not appear in cutomers entity????
so how can i retrive this value or set it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实体框架本身会渲染实际属性,它将创建类型类别的属性。
即:
Customer.Category = new Category()
实体框架将在内部处理引用/外键。
The Entity Framework does render the actual property itself, it will create an property of Type Category.
i.e.:
Customer.Category = new Category()
The Entity Framework will handle the references / foreign keys internally.
对于当前可用的实体框架版本(带有 .NET 3.5 SP1),Colin 的回答是 100% 准确且真实的。
对于即将发布且尚未发布的 EF v2(或 EF 4??)(将在未来随 .NET 4.0 一起发布),EF 团队添加了他们所谓的“外键关联”,这本质上将允许您只需指定外键值(例如 CategoryID),而不必创建/加载/分配整个关联实体。
在这些优秀的帖子中查看更多内容:
免责声明:这是有关尚未发布的产品的预发布信息,尚未正式宣布交付日期 - 您可以下载目前是 Beta1。
马克
Colin's answer is 100% accurate and true - for the currently available release of the Entity Framework (with .NET 3.5 SP1).
For the upcoming and not-yet-released EF v2 (or EF 4??) that will ship with .NET 4.0 sometime in the future, the EF team has added what they call "foreign key associations", which in essence will allow you to just specify the foreign key value (e.g. CategoryID) instead of having to create / load / assign the whole associated entity.
See more in these excellent posts:
DISCLAIMER: this is pre-release information about a not-yet-released product and with no delivery date officially announced - you can download a Beta1 for now.
Marc
你不能这样做吗?
Can't you do it this way ?
如果您想自行查看外键,则必须使用 .NET Framework 4 不少于
在 .NET 3.5 中,您会发现对外键类的引用,而不是外键本身
IF you want to see the foreign key it self you must use .NET framework 4 not less
in .NET 3.5 you'll find a reference to foreign key's class not the foreign key it self