手动将导航属性添加到实体框架
我需要在两个实体 TableA 和 TableB 之间添加导航属性
TableA
ID : Primary Key
Code: String (Allows Null)
TableB
BID: Primary Key
Code: String (Allows Null)
现在我想向这些实体添加导航属性,这些实体与不是外键。谁能告诉我这怎么可能
I need to add a navigation property between two Entities TableA and TableB
TableA
ID : Primary Key
Code: String (Allows Null)
TableB
BID: Primary Key
Code: String (Allows Null)
Now I want to add a navigation property to these Entities which are related by the code which is not a foreign key. Can anyone tell me how this is possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是不可能的,因为代码在您的任何表中都不是 PK。导航属性遵循与数据库关系相同的规则 - 在主表中,您必须使用 PK,并且独立地指定 FK。数据库还提供在主表中选择唯一键的功能,但 EF 尚不支持唯一键。
It is not possible because code is not PK in any of your tables. Navigation properties follows same rules as database relations - in principal table you must use PK and in dependent you specify FK. Databases also offers selecting unique key in principal table but EF doesn't support unique keys yet.