How to de-attach an entity from a Context in Entity Framework?

anencemania

New Member
I use EF 4.1 with Repository and DbContext.. POCO with T4 template.For every Repository I use a separate DbContext.I need to update an object with has a related property, at the moment I receive this error\[code\]An entity object cannot be referenced by multiple instances of IEntityChangeTracker.\[/code\]I suppose my problem is beacuse \[code\]eventObj\[/code\] and \[code\]candidate\[/code\] are created from different Repositories.So i'm trying to solve the problem with this code, with no success.My question?
  • How do I get rid of this error?
  • Is is possible remove the candidate from its context?\[code\]public void UpdateAddingCandidate(Event eventObj, Candidate candidate){ Event updatedEvent = new Event(); Candidate updatedCandidate = new Candidate(); updatedEvent = eventObj; updatedCandidate = candidate; updatedEvent.Candidate = updatedCandidate; db.Entry(updatedEvent).State = EntityState.Modified; }\[/code\]
 
Back
Top