It's quite a simple question: When someone click on "Edit Plan" in my ASP.NET MVC project - He doesn't edit but create a new plan with. You can see it more clearly in my answer to my qeustion here: How do I duplicate an object?
Now I want to do the same thing to its references, and I did it like that:
var featurePlans = db.FeaturePlanBaseSet.Where(f => f.PlanId == plan.Id).ToList();
db.PlanSet.AddObject(plan);
db.SaveChanges();
for (var i = 0; i < featurePlans.Count(); i++ )
{
featurePlans[i].Plan = plan;
db.FeaturePlanBaseSet.AddObject(featurePlans[i]);
}
Plan is added when I do AddObject
, but Feature
isn't.
I get this error:
An object with the same key already exists in the ObjectStateManager. The existing object is in the Unchanged state.
I'll be glad to know why does it happens.