views:

262

answers:

2

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  A: 

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

Craig Stuntz
Thanks. My ParentconditionId wasn't nullable.
burnside
+2  A: 

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

J.W.
Thanks for the link. I've been on this guy's blog before but have never seen the project download.
burnside