self referemce many to many nhibernate mapping convention

203 Views Asked by At
public class Node
{
   public virtual int Id {get; set;}
   public virtual string Name {get; set;}
   public virtual IList<Node> Ancestors {get; set;}
   public virtual IList<Node> Descendants {get; set;}
}

how to setup the mapping convention for this case?

thank you

1

There are 1 best solutions below

0
On

Are you sure you want a convention? I am going to guess you just want a fluent mapping. Here's an example from the last time I helped someone with this:

public class CustomerMap : ClassMap<Customer> 
{ 
    public CustomerMap() 
    { 
        Id(x => x.CustomerId); 
        Map(x => x.Birthday); 
        Map(x => x.FirstName); 

        HasManyToMany(x => x.Parents) 
            .ParentKeyColumn("ChildID") 
            .ChildKeyColumn("ParentID") 
            .Inverse(); 

        HasManyToMany(x => x.Children) 
            .ParentKeyColumn("ParentID") 
            .ChildKeyColumn("ChildID"); 
    } 
} 

See here for the original thread. That thread has a link to an example project I made for demonstrating self referencing many-to-many relationships, which is here.