0

Silverlight 4, Entity Framework 4 및 WCF Data Services를 사용하고 있습니다. 재생 목록 개체가 있다고 가정 해 보겠습니다. Playlist 객체는 표시 객체에 대해 0에서 1 탐색 속성으로 표시되는 속성 및 외래 키를 포함합니다. 데이터베이스에는 Display_Id 열이 있습니다.WCF 데이터 서비스에서 전체 개체가 아닌 외래 키 저장

데이터베이스에서 전체 표시 개체를로드하지 않고 재생 목록을 저장하고 display_id를 직접 설정하려고합니다 (쿼리 문자열의 디스플레이 ID가 표시됨). 나는 시도했다 :

playlist.Display = new Display() { Id = 3136 }; 
// this SetLink throws an exception that the Display is not yet tracked  
context.SetLink(playlist.Display, "Display", playlist); 
// or i've tried, but get an error: Entities in 'EDM.Displays' participate in the //'DisplayX' relationship. 0 related 'X' were found. 1 'X' is expected 
context.AddToDisplays(playlist.Display); 
context.SetLink(playlist, "Display", playlist.Display); 

내가 내 EDM을 변경해야하거나 클라이언트 측에서이 작업을 수행 할 수있는 방법이 있습니까?

답변

1

당신은 데이터베이스를 호출하지 않고이 로컬로 실행되는 것 ObjectSet

Display d = new Display{ id = 3136 }; 
context.Displays.Attach(d); 

에 객체를 연결해야하고, 당신이

필요에 따라 다음 작업을 할 수있는 모든 중 먼저 다른 방법이 : 오브젝트의 재생 목록 개체를 포함 EntityKeyValues의 DysplayReference가 null 인 경우 EntityKeyValues의 키를 바꿉니다.

+0

AddToDisplays 메서드가 컨텍스트에 첨부한다고 생각합니다. – Aligned

+0

EF는 스스로 돕는 사람들을 돕습니다.) – ASpirin

관련 문제