How can "An entity object cannot be referenced by multiple instances of IEntityChangeTracker" be resolved?



I have an Ado.Net EF model. When I try to add the entities because of a one-to-many relation, I get an error.

"More than one instances of IEntityChangeTracker may not reference the same entity object."

Any clue?

something resembling

Template template = new Template();
while (from < to)
    Course course = new Course();
courseEntities.AddToTemplate(template); // Problem line
3/6/2009 7:38:42 PM

Accepted Answer

Before I began storing the data context in the HttpContext.Items Property, I was receiving this message. This indicates that the current web request may make use of the same data context. This will prevent the occurrence of duplicate data contexts referencing the same things.

This article about Management of DataContext Life is excellent.

Hope it's helpful.


3/6/2009 9:20:35 PM

Popular Answer

"template" has already been added to courseEntities or in another context, or anything that it refers to. Although I can't see anything in the code you provided to support it, it is undoubtedly taking place. Perhaps part of the code you've cut has it. Examine the EntityState of the properties of "template" as well as the EntityState property of "template" in the debugger. You should be able to determine which entity instance is present in a context using this.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow