2010-07-18 37 views
3

我有兩個表:有沒有辦法在nhibernate中進行反向查找?

  1. 組件
  2. ComponentDependencies

ComponentDependencies有兩列:COMPONENTIDComponentDependencyID。 (外國鍵進入Id字段的組件

我用流利的nhiberate和我有我的組件對象:

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

,並在我的ComponentMap類,我有NHibernate的地圖:

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

所以當我有一個組件對象,我可以看到它的依賴項的列表。

無論如何,我可以有一個額外的財產有「反向」名單。我的意思是,我想了一個名爲「DependentOf」屬性,這也是一個

IList<ComponentDependency> 

它具有所有這哪裏電流分量是關係依賴組件的項目?

回答

1

這看起來像一個材料清單問題,其中組件通過ComponentDependencies鏈接表具有與其自身的多對多關係。您可以通過交替選擇哪個列作爲父鍵列來映射兩個關係方向:

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

HasManyToMany(x => x.DependentOf).Table("ComponentDependencies") 
    .ParentKeyColumn("ComponentDependencyId").ChildKeyColumn("ComponentId"); 
相關問題