I have a very special NHibernate mapping case. The class has a reference to itself.
public class MyClass
{
public Guid Id { get; set; }
public MyClass SelfReference { get; set; }
}
The data base table has a foreign key field on the primary key of the same table. And event worse, this self reference can be null.
Is that possible to map and how can this be done?
one-to-one can be used to synchronize primary keys and is used rarely, in my experience many-to-one is the most "natural" association for "normal" references:
<many-to-one name="SelfReference" class="MyClass" column="SelfReference_FK" />
Seems like you're willing to map a tree:
http://nhibernate.hibernatingrhinos.com/16/how-to-map-a-tree-in-nhibernate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With