0

Windows Phone 7에서 WCF 데이터 서비스를 사용하고 있습니다. 한 번 클릭하여 관계형 데이터를 저장하고 싶습니다. 어떻게해야합니까?wcf 데이터 서비스가 한 번의 클릭으로 관계형 데이터 저장

그것은 생각의 2 테이블 : 종류와 제품

I 데이터 UI를 저장할

:

Cateogry 표에서

: -
카테고리 ID : (자동 증가)
범주 : ABC

제품에서 표 : -
ProductId :-(자동 증가)
카테고리 ID : -? 저장을 클릭 버튼을

XYZ :

내가 충당 테이블의 데이터 위에 삽입 할, 내가 그걸 어떻게 할 수
ProductsName을 (확실하지가 어떻게 검색 할 수 있습니다)? 하나 개의 테이블에 데이터 추가에 대해 나는 다음과 같은 코드를 사용하고

: 하나로, OData 관계에서

try 
{ 
    context = new NorthwindEntities(NorthwindUri); 
    context.AddToProducts(product); 
    context.BeginSaveChanges(new AsyncCallback((result) => 
    { 
     bool errorOccured = false; 

     // Use the Dispatcher to ensure that the 
     // asynchronous call returns in the correct thread. 
     Deployment.Current.Dispatcher.BeginInvoke(() => 
     { 
      context = result.AsyncState as NorthwindEntities; 

      try 
      { 
        // Complete the save changes operation and display the response. 
        DataServiceResponse response = context.EndSaveChanges(result); 

        foreach (ChangeOperationResponse changeResponse in response) 
        { 
         if (changeResponse.Error != null) errorOccured = true; 
        } 
        if (!errorOccured) 
        { 
         MessageBox.Show("The changes have been saved to the data service."); 
        } 
        else 
        { 
         MessageBox.Show("An error occured. One or more changes could not be saved."); 
        } 
       } 
       catch (Exception ex) 
       { 
        // Display the error from the response. 
        MessageBox.Show(string.Format("The following error occured: {0}", ex.Message)); 
       } 
     }); 
    }), context); 
} 
catch (Exception ex) 
{ 
    MessageBox.Show(string.Format("The changes could not be saved to the data service.\n" 
     + "The following error occurred: {0}", ex.Message)); 
} 

답변

1

이 외부 키로 표시되지 않습니다는, 대신에 그들은 탐색 속성으로 표시됩니다. 그런 다음 클라이언트 라이브러리에서 링크를 조작하여이를 조작합니다. 이 기사를 살펴보십시오. http://msdn.microsoft.com/en-us/library/dd756361(v=vs.103).aspx 데이터를 수정하는 여러 메서드를 호출 한 다음 SaveChanges를 호출하여 모든 데이터를 서버로 보낼 수 있습니다. 서버가 참조 무결성을 필요로하고 예를 들어 두 개의 관련 엔티티를 동시에 추가하는 경우 SaveChanges (일괄 처리)를 사용해야 할 수도 있습니다 (클라이언트가 한 요청에서 모든 것을 보내도록하므로 서버 단일 트랜잭션으로 처리).

관련 문제