views:

16

answers:

1

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 => 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?

A: 

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.

David M
They are added to both sides. That should be ok too?
Bertvan
Yes, it should be.
David M
I have set this as an answer. The problem is a bit more complicated, and this anwer helped me conclude that there was nothing wrong with the mappings, but that I had to look elsewhere.
Bertvan

related questions