Direction of Many-to-many mapping
Hi,
How are you?
I have recently discovered Fluent NHibernate, and there is something that I don't undestand about the way Automapping resolve many-to-many relationships.
Initially I thougth the mapping would be bidirectional, but then I discover that is unidirectional and I don't know how to specify the
direction.
Is there any way to do it?
Thank you very much,
Marta.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Devon Lazarus on 05 May, 2010 02:46 PM
The mapping is only bi-directional if you specify the collection in another entity.
"Setting the direction" is kind of a misnomer in my opinion. You're not really setting the direction, you're telling NH which side of the collection is responsible for cascading the save/update/delete call.
If you want to control this, you would use .Inverse() on the side of the collection you do not want to cascade from:
Using this mapping, MyEntity objects added to EntityOne would not be saved in the database unless they were also added to the EntityTwo.Entities collection.
hth,
-devon
James Gregory resolved this discussion on 16 May, 2010 05:24 PM.