Reputation: 141
I have a table that has a primary key as a combination of 3 columns 1. AcctNum (string) 2. SrvID (int) 3. RevNum (int)
What I am doing in my code is
When I do context.TableName.AddObject(newRow) it throws an exception "An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key."
Even though in the new row I am changing the RevNum to have a unique key. Can someone please tell me what I am doing wrong here?
Upvotes: 1
Views: 456
Reputation: 141
I resolved this issue myself. The problem is about using AutoMapper to map from an existing entity instance (mapped table row) to a new entity instance (new table row being created).
I stopped using AutoMapper and mapped each property manually one by one and it worked just fine!
Another post with a similar issue: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key
Upvotes: 1