How to find out which object is inside the ObjectStateManager more than once
Hi i am getting the following error:
AcceptChanges cannot continue because the value of the object conflicts with another object in the ObjectStateManager. Make sure the key values are unique before calling AcceptChanges.
Now I'm trying to fix this, but I need to figure out exactly which entity is giving me problems, so I know where to look.
I know what the error is and I know how to solve it, but I don't know how to find out which object is double.
+1
source to share
1 answer
You can check ObjectStateManager to get all changed objects. the code looks something like this:
var lst = context.ObjectStateManager
.GetObjectStateEntries(EntityState.Added |
EntityState.Modified |
EntityState.Deleted);
var res = lst.GroupBy(c => c.EntityKey).Where(c=> c.Count() > 1);
+2
source to share