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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.