Same table relationship in Entity Framework

c# entity-framework

Question

Is it possible to have an association mapping a table to itself?

e.g.

Table:  
ConditionId  
ConditionName 
... 
...  
ParentConditionId

where we can have many ParentConditionIds each mapping to the same ConditionId.

I've tried a one to many mapping but I'm getting an error when there is no children.

1
9
1/4/2010 12:34:05 AM

Accepted Answer

Yes it is possible. Put the FK in your database and the wizard will map it correctly. Make sure ParentConditionId is nullable.

16
5/5/2009 1:47:16 PM

Popular Answer

Take a look tutorial which can be download here . It explains in detail how to model self-reference table.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow