0

How can i go about defining a same table relation mapping (mappingbycode) using Nhibernate

for instance let's say I have a class:

public class Structure{
 public int structureId;
 public string structureName;
 public Structure rootStructure;
}

that references the same class as rootStructure.

 mapper.Class<Structure>(m =>
            {
                m.Lazy(true);
                m.Id(u => u.structureId, map => { map.Generator(Generators.Identity); });
                m.Property(c => c.structureName);
                m.? // Same table mapping 
}
 ;

Thanks

mircea .
  • 241
  • 5
  • 15

1 Answers1

1

there is no special mapping for recursive mappings i am aware of. Just map it like you would map a collection of a different class. In your case this should work (untested though):

m.OneToOne(c => c.rootStructure, a => a.Lazy(LazyRelation.Proxy))

NHibernate will assume that the foreign key for this relation is stored on column rootStructure of the table associated to that class.

Dirk Trilsbeek
  • 5,873
  • 2
  • 25
  • 23