views:

44

answers:

1

i have two tables:

  1. Components
  2. ComponentDependencies

ComponentDependencies has two columns: ComponentId and ComponentDependencyID. (both foreign keys into Id field of Component table.

i am using fluent nhiberate and i have my component object having:

 public virtual IList<ComponentDependency> Dependencies { get; set; }

and in my ComponentMap class, i have nhibernate map:

HasMany(x => x.Dependencies)
            .AsBag().Inverse();

So when i have a component object, i can see a list of its dependencies.

Is there anyway i can have an additional property have the "reverse" list. What i mean is that i want a property called "DependentOf" which is also a

  IList<ComponentDependency>

which has all of the items where this current component is the dependent component in the relationship?

+1  A: 

This looks like a bill-of-materials problem with Components having a many-to-many relationship to itself through the ComponentDependencies linking table. You can map both relationship directions by alternating which column is the parent key column:

HasManyToMany(x => x.Dependencies).Table("ComponentDependencies")
    .ParentKeyColumn("ComponentId").ChildKeyColumn("ComponentDependencyId");

HasManyToMany(x => x.DependentOf).Table("ComponentDependencies")
    .ParentKeyColumn("ComponentDependencyId").ChildKeyColumn("ComponentId");
Jamie Ide