Sto tentando di collegare un'entità all'ObjectContext. Quando faccio così, il seguente InvalidOperationException è gettato:Impossibile associare un'entità distaccata: "Un oggetto con la stessa chiave esiste già in ObjectStateManager"
An object with the same key already exists in the ObjectStateManager.
The ObjectStateManager cannot track multiple objects with the same key.
ho controllato nel gestore oggetto di stato e la voce non esiste:
//Data context is actually the object context.
ObjectStateEntry contact;
while (//Should only work once since it should be true if the item was attached
!DataContext.ObjectStateManager.
TryGetObjectStateEntry(Contact, out contact)
)
DataContext.Attach(Contact); //Here is the exception thrown.
o guardare questo esempio astratto e dimmi se ha senso:
EntityState state = Contact.EntityState; //Detached
DataContext.Attach(Contact); //Throws the exception.
DataContext.AttachTo("Entities.Contacts", Contact); //Throws the Exception
var detached = DataContext.ObjectStateManager.
GetObjectStateEntries(EntityState.Detached);
//InvalidArgumentException - detached entities cannot be in the obj state mgr
Anche le risposte in VB sono benvenute.
Im che affronta un problema simile, puoi fornire un esempio di come si può vedere l'intero grafico dell'oggetto che si sta collegando al contesto e verificare se ci sono oggetti con chiavi duplicate? – Eduard