views:

78

answers:

2

Hello,

I have a User with related Permissions. Here is what I want:

I create a User and add a permission to the User.Permissions collection. It gets saved and everything happens as expected.

Then I edit the user and remove the permission. A new user object is then created and the permissions collection is empty. The identifier and version of this new user object are set to the relevant values and the user object is updated.

But the existing permission is not removed.

So I would like NHibernate to always delete the permissions collection and re-insert all the items in it.

How do I set this up? I am using the fluent api.

Regards, Eben

A: 

I think that when you edit you shouldn't create a new object - that's why nhibernate doesn't remove the permission collection.

Load the existing user from the DB, and then do a .Remove() on his permissions collection.

sirrocco
A: 

SaveOrUpdateCopy did the trick

related questions