views:

37

answers:

1

I am getting the following error in an Asp.Net Castle ActiveRecord app when trying to update an object:

"a different object with the same identifier value was already associated with the session"

I've looked up and down my code to see where else the object might have been created but I'm not seeing it. This is baffling as I have the exact same code on another page that works fine on updates

Now I'm thinking of trying to see where this other object is in the Session and either kill it or find out how it got into the session. How can I find this object?

[Update] Ok, I finally found where the object is being called. However, I would still like to know how to find objects in the session for future reference.

A: 

If you need to check if an object is in your session you're probably doing things the wrong way from the start. Reconsider how you manage your session and persistent objects.

That said, you might want to try ISession.Contains(), but IIRC it will only work if you check with the exact instance that is stored in the session.

Mauricio Scheffer
The issue was coming from using those objects in a drop down list. Those objects in the drop down don't need to be persisted and I'm not sure how to get the objects to load and forget about them other than explicitly calling Evict on the objects as soon as they aren't needed anymore. I guess the proper term for them would be transient?
KeithA
@KeithA: consider databinding against DTOs, otherwise call Evict on the persistent objects.
Mauricio Scheffer