2010-05-28 28 views
0

當保存我的多對多關聯實體時,實體將保存成功。然而結合表保持爲空:fluentnhibernate ManyToMany不會將記錄添加到聯結表

上產品側映射(ProductMap.cs)

HasManyToMany(x => x.Pictures) 
.Table("Product_Picture") 
.ParentKeyColumn("Product") 
.ChildKeyColumn("Picture") 
.Cascade.All() 
.Inverse() 

這將產生以下的xml:上側圖片

<bag cascade="all" name="Pictures" table="Product_Picture"> 
    <key> 
    <column name="Product" /> 
    </key> 
    <many-to-many class="...Picture..."> 
    <column name="Picture" /> 
    </many-to-many> 
</bag> 

映射(PictureMap.cs)

HasManyToMany(x => x.Products) 
.Table("Product_Picture") 
.ParentKeyColumn("Picture") 
.ChildKeyColumn("Product") 
.Cascade.All(); 

這產生以下xml:

<bag inverse="true" cascade="all" name="Products" table="Product_Picture"> 
    <key> 
    <column name="Picture" /> 
    </key> 
    <many-to-many class="...Product..."> 
    <column name="Product" /> 
    </many-to-many> 
</bag> 

任何想法?

+0

在啓動代碼塊之前,您需要一個空白行。 – 2010-05-28 14:11:24

+0

好的謝謝:),現在我只需要一個問題的答案 – Bertvan 2010-05-28 14:24:05

+0

正如我所建議的,我們將需要看到更多的代碼... – 2010-05-28 15:42:08

回答

0

您必須確保將要添加到Picture對象上的集合中,這是您尚未聲明爲Inverse()的關係的方向。增加關係的另一方不會導致他們被持續。

如果您正在這樣做,或者正在添加到雙方,請發佈一些您正在操作的代碼並嘗試保存這些對象。

+0

它們被添加到雙方。那應該也沒關係? – Bertvan 2010-05-28 14:03:14

+0

是的,應該是。 – 2010-05-28 14:11:59

+0

我已將此設置爲答案。 這個問題有點複雜,而這個問題幫助我得出結論,映射沒有任何問題,但我不得不在其他地方尋找。 – Bertvan 2010-06-02 09:36:19

相關問題