Is there a way to do a reverse lookup in nhibernate?

I have two tables:

  • Components
  • ComponentDependencies

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

I am using fluent nhiberate and I have a 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, I can see a list of its dependencies.

In any case, I may have an additional property that has a list of "reverse". I mean, I want a property called DependentOf, which is also

  IList<ComponentDependency>

, ?

+3
1

, " " ComponentDependencies. , :

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

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

Source: https://habr.com/ru/post/1755162/


All Articles