2010-01-21 7 views
1

여기 상황이 있습니다. 나는이 같은 (짧은) 내 EF 데이터 모델은 실버 라이트 3와 ADP.NET 데이터 서비스 1.5 CTP2을 사용하고 있습니다 :ADO.NET Data Services - 추적 된 목록간에 변경 내용을 전파 하시겠습니까?

CmsProfile 
     Id 
     Name 

CmsEvent 
     Id 
     Title 

CmsProfileEventLink 
     Id 
     ProfileId 
     EventId 

는 그래서 많은 <이 - 사람과 이벤트 사이> 많은 관계. 당신은 내가 Expand() 실제로 다음 단계를 버리고 나에게 이벤트 링크 정보를 얻을 얻을 수없는 것을 알 수

private void AsyncLoadEventsKickoff() 
{ 
    DataServiceQuery<CmsEvent> theQuery = dashboardService 
     .CmsEvents 
     .Expand("CmsProfileEventLinks") 
     .AddQueryOption("$orderby", "Title"); 

    theQuery.BeginExecute(
     delegate(IAsyncResult asyncResult) 
     { 
      Dispatcher.BeginInvoke(
       () => 
       { 
        DataServiceQuery<CmsEvent> query = 
         asyncResult.AsyncState as DataServiceQuery<CmsEvent>; 
        if (query != null) 
        { 
         //create a tracked DataServiceCollection from the 
         //result of the asynchronous query. 
         events = DataServiceCollection 
          .CreateTracked<CmsEvent>(dashboardService, 
           query.EndExecute(asyncResult)); 

         AsyncLoadTracker(); 
        } 
       } 
      ); 
     }, 
     theQuery 
    ); 
} 

: 나는 실버 내에서 이벤트를로드 할 때, 나는이 방법을한다. 이벤트 링크 레코드가 있는지 여부 만 알려줄 것입니다.

모든 이벤트를 표 (SelectionGrid)에 넣었습니다.이 이벤트를 클릭하면이 이벤트와 관련된 사람들과 다른 표 (EventsGrid)를로드하려고합니다. 그리드를 CmsProfileEventLink 개체로로드 한 다음 DataMemberPath을 프로파일 이름으로 드릴 다운하여이 작업을 수행합니다. 이론적으로 그리드가 나를 위해 새 링크를 추가 할 수 있습니다. 행을 추가 할 때 Id을주고 CmsEvent을 현재 이벤트로 설정하고 Profile 및 blammo - new 링크 레코드에 대한 사용자 입력을 가져옵니다.

완벽한 세계에서 나는 단지 peopleGrid.ItemsSource = EventsGrid.Selecteditem.CmsPeopleEventLinks을 설정할 수 있으며 모든 것이 예상대로 작동 할 것입니다. 그러나 확장이 그 깊은 것을 얻지 못했기 때문에, 나는 할 수 없다.

해결 방법으로 모든 CmsProfileEventLinks을 동일한 방법으로 "링크"변수에로드했습니다. 당신이 이벤트를 선택하면 그래서 난이 (추한, 못생긴, 추한) 표시하는 프로파일을 ...

변화가 EventsGrid 내에서 이루어진 경우는 다시 전파되지 않습니다
private void Sync_EventsGrid() 
{ 
    var item = SelectionGrid.SelectedItem as CmsEvent; 

    if (item.CmsEventProfileLinks != null) 
    { 
     DataServiceCollection<CmsEventProfileLink> x = 
      DataServiceCollection 
       .CreateTracked<CmsEventProfileLink>(
        dashboardService, 
        links.Where(p => p.CmsEvent == item)); 

     EventsGrid.ItemsSource = x; 
    } 
} 

문제는 ... 링크 문맥은 모두 DataService 컨텍스트를 공유하지만 그물 결과? 다른 이벤트를 선택하여 돌아 오면 EventsGrid에 최근에 추가 된 레코드가 표시되지 않습니다. 응용 프로그램을 새로 고치면 데이터베이스에서 링크를 다시 읽도록 강요합니까? 그것은 그것을 집어 든다. 단순히 두 번째로의 링크 속성을 전달할 수 있도록

는 그래서 초기 로드에 CmsEvent 레코드의 2 단계 확장 을 다음 ...

  1. 있는 방법 중 하나를 필요 그리드 (컨텍스트를 보존)

  2. 나던 독립 한 컨텍스트를 생성하지 않습니다 "링크"의 필터링 보기를 얻을 수있는 더 좋은 방법갱신

  3. "링크"가 새로 고침해야 객체를 통지하는 방법, 바람직 비동기 호출을 통해 서버에 모든 방법 돌아갈를 시작하지 않고 - 데이터가 명확하게 이 되었기 때문에 로컬 컨텍스트에서 업데이트되었습니다.

힌트 :

답변

1

당신 수 확장 된 특성을 통해 루프, 아이를 확장과 같이 각 하나에 LoadProperty 전화 :

DataServiceQuery<CmsEvent> query 
         = asyncResult.AsyncState as DataServiceQuery<CmsEvent>; 
if (query != null) 
{ 
    //create a tracked DataServiceCollection from the 
    //result of the asynchronous query. 
    events = DataServiceCollection.CreateTracked<CmsEvent>(dashboardService, 
               query.EndExecute(asyncResult)); 
    AsyncLoadTracker(); 

    foreach(var link in events.SelectMany(e=> e.CmsProfileEventLink)) 
    { 
     dashboardService.LoadProperty(link, "CmsPeopleEventLinks"); 
    } 
} 
관련 문제