Hi,
I think the problem is due to the fact that you're fetching the User and the UserAuthorization objects with 2 different sessions, which means that the
regular User and the User that is included in the UserAuthorization ("User"-property) are not one and the same object.
When you pass the
regular User object to the session after having passed the UserAuthorizations to the session, you're getting this error, which is normal.
A
possible solution is to re-assign the User object:
Code:
user = session.Get<User>(user.ID);
This way, you're asking the session to fetch you the user that is currently present in the session (it's cached and you're using the primary key, so you won't have a roundtrip to the database). When you'll execute the delete, you shouldn't have the error any more.
Code:
session.Delete(user);
There are of course other ways to avoid this error, just ensure that you don't use two objects representing the same database record in one session.