fluentnhibernate ManyToMany does not add records to the junction table
When saving my many-to-many related entities, the entities are saved ok. However the junction table stays empty:
Mapping on Product side (ProductMap.cs)
HasManyToMany(x => x.Pictures)
.Table("Product_Picture")
.ParentKeyColumn("Product")
.ChildKeyColumn("Picture")
.Cascade.All()
.Inverse()
This produces the following 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>
Mapping on Picture side (PictureMap.cs)
HasManyToMany(x =>开发者_C百科; x.Products)
.Table("Product_Picture")
.ParentKeyColumn("Picture")
.ChildKeyColumn("Product")
.Cascade.All();
This produces the following 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>
Any ideas?
You must make sure you are adding to the collection on the Picture
object, which is the direction of the relationship you have not declared as Inverse()
. Adding to the other side of the relationship will not cause them to be persisted.
If you are doing this, or are adding to both sides, then please post some of the code where you are manipulating and trying to save these objects.
精彩评论