엔티티의 네비게이션 속성이 끝났다는 생각이 들지 않는 응용 프로그램에서 매우 이상한 문제가 발생했습니다. 엔티티가 실제로있을 때 다른쪽에 있습니다. 네비게이션 속성은 일대일 탐색이며 과거에는 일대일 속성에 다른 문제가 있었음을 알고 있습니다. 따라서 이상한 케이스 버그를 만났을 수도 있습니다.다중 캐시 복원/가져 오기 후 Dev Force Navigation 등록 정보의 문제
가장 단순한 방법으로 문제를 재현하려고 시도하면서 entityManager.CacheStateManager.RestoreCacheState (someCacheState)를 두 번 연속 수행하여이를 재현 할 수 있음을 발견했습니다. 두 번하면 문제가 발생하지만 한 번 만 수행하면 문제가 발생합니다. 우리의 응용 프로그램에서는 캐시 상태를 복원하는 중이고 문제와 관련된 것으로 보입니다. 나는 우리가 그것을 두 번이나 복원하고 있다고 생각하지 않는다. 어느 쪽이든, 이렇게하는 것이 좋을 것 같습니다.
또한 실제 응용 프로그램에서는 두 엔터티 (일대일 관계에 참여하는 두 엔터티) 목록에서 ImportEntities를 수행하여 두 번의 두 가지 문제를 재현 할 수 있습니다. 이 경우 문제를 재현하기 위해 동일한 캐시 상태를 두 번 복원해야한다는 이상한 일을 할 필요가 없습니다. 가져 오기를 두 번만 수행하면됩니다. 불행히도, 나는 깨끗한 솔루션으로 이중 가져 오기를 재현 할 수 없었습니다.
private static void TestMultipleImports()
{
//Any database with a one-to-one should work. I'm using Adventure Works here but I've modified
// it to have a one-to-one relationship. For each Contact there are 0 or 1 Contact Details
// (they both have ContactID as the Primary Key)
var mainEm = new AdventureWorksEntities();
//Add a Contact and a Contact Detail with the same SID
var contact = new Contact {ContactID = 1};
var detail = new ContactDetail {ContactID = 1};
mainEm.AttachEntity(contact);
mainEm.AttachEntity(detail);
//DevForce correctly matched up the entities so navigating from Contact to Detail or
// from Detail to Contact works as expected
Assert.AreSame(detail, contact.ContactDetail);
Assert.AreSame(contact, detail.Contact);
//In another entity manager, add the same Contact and Details
var altEm = new AdventureWorksEntities();
altEm.AttachEntity(new ContactDetail {ContactID = 1});
altEm.AttachEntity(new Contact {ContactID = 1});
//Use our helper method to import everything from our alternate EM into the main one
ImportAll(altEm, mainEm);
//Verify the navigations are still working
Assert.AreSame(contact, detail.Contact);
Assert.AreSame(detail, contact.ContactDetail);
//Now do a similar import except we'll import into the dummy EM before importing into the main EM.
// This 'double import' seems to cause the problem. It would also break if we imported twice into
// main EM.
var dummy = new EntityManager();
ImportAll(altEm, dummy, mainEm, mainEm);
//Verify once more. This one will pass ...
Assert.AreSame(contact, detail.Contact);
//...but this will fail. The Contact Detail is in the Entity Manager and it can navigate to its related
// Contact...but for some reason, the Contact can't navigate to the Detail any longer. Instead of
// being the expected Contact Detail entity, it is a Null Entity
Assert.AreSame(detail, contact.ContactDetail);
}
//Perhaps a bit of an odd way to copy entities between entity managers but it seems like this should be a
// reasonable thing to do
private static void ImportAll(EntityManager source, params EntityManager[] destinations)
{
var ecs1 = source.CacheStateManager.GetCacheState();
foreach (var destination in destinations)
{
destination.CacheStateManager.RestoreCacheState(ecs1, RestoreStrategy.Normal);
}
}
우리는 데브 포스 2012 버전 (이 글을 쓰는 현재) 최신 실행 : 7.2.3 여기
몇 가지 샘플 코드 (가) 예상 동작을 보여 실제 동작을 보여주고있다.
죄송합니다. 귀하가 DF 2010 또는 2012 중 어느 것을 사용하고 있는지 기억이 없습니다. –
해당 정보를 포함해야합니다. 질문을 업데이트했지만 우리는 DF2012에 있습니다 - 7.2.3. –
AW2000에서 Employee-SalesPerson 1 : 1 관계로 이것을 재현 할 수 없으며 RestoreCacheState 및 ImportEntities 둘 다에서 올바른 동작을 볼 수 없습니다. 아마도 문제는 모델에서 관계가 정의되는 방법에 있습니다. Contact-ContactDetail 엔터티에 EDMX를 게시 (또는 보내주십시오) 하시겠습니까? 또한 CloningFns.CloningMethod를 설정 했습니까? –