Reputation: 196459
i have two tables:
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?
Upvotes: 3
Views: 169
Reputation: 49251
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");
Upvotes: 1