클라이언트 쪽 EntitySet에 추가 할 때 오류가 발생합니다. 다음 코드는 간헐적으로 Add
메서드에서 실패합니다.예기치 않은 "동일한 ID를 가진 엔터티가이 EntitySet에 이미 있습니다"?
// On the DB side this has a primary key field of IDENTITY(1,1) called Id
var map = new EpisodeDictionaryMap();
map.DictionaryName = dictionary; // String
map.Section = section; // String
map.DictionaryVersion = version; // Int32
episode.EpisodeDictionaryMap.Add(map);
나는 또한 모든 이제 다시 전에 모든이 코드를 호출하지 (다른 사람의 사이에) Episode
에 대한 EntitySets에 Clear()
및 EpisodeDictionaryMap
를 호출하지만 해요, 때 응용 프로그램 내에서 다른 화면으로 사용자 변경됩니다. 이것은 최근의 변화이므로 문제의 일부가 될 수 있습니다. 그것은이 나타날 것 DomainContext의 EpisodeDictionaryMap 수집을 조사하면
는 가끔 전에 절약에 기대하는 것처럼, 0
의 ID와 각 인스턴스 사실 여러에서 '새'EpisodeDictionaryMap이 있고, 이러한 경우에 저장 문제없이 완료 올바른 ID가 클라이언트 측 엔티티에 지정됩니다.
EntitySet에 ID가 0
인 항목이 여러 개있는 것은 문제가되지 않는다는 것을 감안할 때 (적어도 "새로운"상태 인 동안은) 나는 그렇지 않습니다. 오류 메시지가 무엇을 말하려고하는지 이해하십시오.
작곡이 문제가 될 수있는 몇 가지 관련 질문에 주목했지만 사용하지는 않습니다. 에피소드 참조 자체를 제외하고는 다른 외부 키 참조도 없으며 때로는이 오류가 발생할 수도 있습니다.
제안, 생각? 많은 감사합니다!
편집 :
이 이전체 예외 (더 내부 예외가 존재하지 않는)
System.InvalidOperationException occurred
Message=An entity with the same identity already exists in this EntitySet.
StackTrace:
at System.ServiceModel.DomainServices.Client.EntitySet.AddInternal(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.<Add>b__5(EntitySet l, Entity e)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.VisitEntityCollection(IEntityCollection entityCollection, PropertyInfo propertyInfo)
at System.ServiceModel.DomainServices.Client.EntityVisitor.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.VisitEntityRef(IEntityRef entityRef, Entity parent, PropertyInfo propertyInfo)
at System.ServiceModel.DomainServices.Client.EntityVisitor.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.VisitEntityRef(IEntityRef entityRef, Entity parent, PropertyInfo propertyInfo)
at System.ServiceModel.DomainServices.Client.EntityVisitor.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.Visit(Entity entity)
at System.ServiceModel.DomainServices.Client.EntitySet.AddAttachInferrer.Infer(EntityContainer container, Entity entity, Action`2 action)
at System.ServiceModel.DomainServices.Client.EntitySet.Add(Entity entity)
at System.ServiceModel.DomainServices.Client.EntityCollection`1.Add(TEntity entity)
at TangoSoft.Client.EpisodeExtensions.SaveDictionaryVersion(Episode episode, String dictionary, String section, Int32 version)
테이블 내용을 보았습니까?아마도 자동 생성 된 PK가 간헐적으로 기존 행과 충돌합니다 – Rob
키는 실제로 클라이언트 코드에 의해 생성되지 않고 DB 삽입시 생성되므로 실제로 이해가되지 않습니다. 그렇더라도 클라이언트의 ID를 별개이지만 사용하지 않는 값 (-1234)으로 설정하면 오류가 발생하므로 불만을 제기하는 Id 값 자체는 아닙니다. 그것은 내가 오류를 이해하는 데 혼란 스러울 부분입니다. –
당신 말이 맞아요. 나는 당신이 당신의 변화를 다시 DB에 저장하지 않는다는 것을 깨닫지 못했습니다. 비록 당신이라면, DB에서 생성 된 값으로도 PK에서 충돌이 발생할 수 있습니다. 코드에서 외래 키를 다른 위치에 설정 했습니까? 아니면 설정하지 않았습니까? 어디에서'SaveChanges()'를 호출합니까? 나는 예외의 개별 속성 (아마도'InnerException'이 있음)을 검사하고 단서를 찾아 디버깅을 계속할 것이다. – Rob