Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I see what's in the ObjectStateManager when debugging?

BACKGROUND

I'm having some trouble with updating an entity in EF. I keep getting this error:

"An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key"

I am fully aware that there is obviously another entity somewhere that is attached. However, I currently cannot track it down. There is a lot of code and I've spent quite some time on it already. As far as I can see, I am using the AsNoTracking() extension method on all my queries.

WHAT I NEED

My question is this: Is there any way I can see what is actually in the ObjectStateManager at any given time? If I can see the items in there during debugging, I can more quickly track down where this is coming from.

If the above is not possible, I would appreciate any advice on how best to tackle this problem.. it's like a needle in a haystack right now.

like image 542
Matt Avatar asked Oct 13 '12 03:10

Matt


1 Answers

Is there any way I can see what is actually in the ObjectStateManager at any given time? If I can see the items in there during debugging, I can more quickly track down where this is coming from.

You can also see what's in the ObjectStateManager by using the Quick Watch feature of the Visual Studio debugger. The path is:

context -> ObjectContext -> ObjectStateManager -> Non-Public members

like image 159
Eric J. Avatar answered Sep 28 '22 16:09

Eric J.