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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With