简体   繁体   English

实体框架中的相同表关系

[英]Same table relationship in Entity Framework

Is it possible to have an association mapping a table to itself? 是否可以将表格映射到自身?

eg 例如

Table:  
ConditionId  
ConditionName 
... 
...  
ParentConditionId

where we can have many ParentConditionIds each mapping to the same ConditionId. 我们可以在其中有许多ParentConditionIds,每个映射到相同的ConditionId。

I've tried a one to many mapping but I'm getting an error when there is no children. 我尝试了一对多的映射,但是在没有孩子时我遇到了错误。

Yes it is possible. 对的,这是可能的。 Put the FK in your database and the wizard will map it correctly. 将FK放入数据库,向导将正确映射它。 Make sure ParentConditionId is nullable. 确保ParentConditionId可以为空。

Take a look tutorial which can be download here . 看一下可以在这里下载的教程。 It explains in detail how to model self-reference table. 它详细解释了如何建模自引用表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与实体框架相同的表上的关系 - Relationship on same table with Entity Framework 实体框架同一表具有自定义属性的多对多关系 - Entity Framework Many to many relationship of same table with custom properies 实体框架代码优先在同一个表上的多对多关系 - Entity Framework Code-first Many to many relationship on the same table 在 Entity Framework Core 中添加与同一个表具有多个一对一关系的实体时出现堆栈溢出 - Stack overflow when adding an entity with multiple one-to-one relationship with the same table in Entity Framework Core 实体框架一对多关系相同类型 - Entity framework One to many relationship same type Entity Framework Core 3.0 表自关系 - Entity Framework Core 3.0 table self relationship 实体框架和表关系错误输出 - Entity Framework and Table Relationship Error Out 实体框架EDMX关系映射表 - Entity Framework EDMX Relationship Mapping Table 如何在Entity Framework 6 Code First中的同一张表之间创建一对一关系? - How to create one-to-one relationship between same table in Entity Framework 6 Code First? 实体框架表拆分:不在同一类型层次结构中/没有有效的一对一外键关系 - Entity Framework Table Splitting: not in the same type hierarchy / do not have a valid one to one foreign key relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM