Hi,
I have to insert a list of items in entity controller, but while inserting im getting the below error.
public int Insert(AbEntity abEntity, List<AbItemEntity> items)
{
_db.AddToAbEntities(abEntity);
_db.SaveChanges();
foreach (AbItemEntity bs in items)
{
bs.Id = abEntity.Id; // same id for all, its foreign key. even i comment this im getting same error
_db.AddToAbItemEntities(bs); //I'm getting error in this line while the loop enters for 2nd time. I tried with below line, also getting same error.
//items.ForEach(n => _db.AddToAbItemEntities(bs));
_db.SaveChanges();
}
return abEntity.Id;
}
Error: An object with the same key already exists in the ObjectStateManager. The existing object is in the Modified state. An object can ...
Go to the complete details ...