2009-09-08 1 views
0

나는 Silverlight 응용 프로그램을 구현하는 방법에 대한 this 자습서를 따라 왔습니다. 이 자습서에서는 Northwind 데이터베이스를 예제로 사용합니다. 코드 샘플을 사용하여 자습서와 동일한 기능을 구현하여 내 자신의 데이터베이스에 내 응용 프로그램을 보여줍니다. 이 자습서의 마지막 부분에서는 Northwind 데이터베이스의 특정 테이블에 새 항목 및 관련 관계를 추가하는 방법을 보여줍니다.Silverlight 비동기식 Crud Insert : 일대일 관계?

private void addDetail_Click(object sender, RoutedEventArgs e) 
{ 
    // Define a URI that returns the product with the specified ID. 
    Uri productUri = new Uri(svcContext.BaseUri.AbsoluteUri 
     + "/Products(" + this.productId.Text + ")"); 

    // Begin a query operation retrieve the Product object 
    // that is required to add a link to the new Order_Detail. 
    svcContext.BeginExecute<Products>(productUri, 
     OnProductQueryCompleted, null); 
} 

private void OnProductQueryCompleted(IAsyncResult result) 
{ 
    // Use the Dispatcher to ensure that the 
    // asynchronous call returns in the correct thread. 
    Dispatcher.BeginInvoke(() => 
     { 
      // Get the Product returned by the completed query. 
      IEnumerable<Products> queryResult = 
       svcContext.EndExecute<Products>(result); 
      Products returnedProduct = queryResult.First(); 

      // Get the currently selected order. 
      Orders currentOrder = (Orders)ordersGrid.SelectedItem; 

      // Create a new Order_Details object with the supplied FK values. 
      Order_Details newItem = Order_Details.CreateOrder_Details(currentOrder.OrderID, 
       returnedProduct.ProductID, 0, 0, 0); 

      detailsBindingCollection.Add(newItem); 

      // Add the new item to the context. 
      svcContext.AddToOrder_Details(newItem); 

      // Add the relationship between the order and the new item. 
      currentOrder.Order_Details.Add(newItem); 
      svcContext.AddLink(currentOrder, "Order_Details", newItem); 

      // Set the reference to the order and product from the item. 
      newItem.Orders = currentOrder; 
      svcContext.SetLink(newItem, "Orders", currentOrder); 

      // Add the relationship between the product and the new item. 
      returnedProduct.Order_Details.Add(newItem); 
      svcContext.AddLink(returnedProduct, "Order_Details", newItem); 

      // Set the reference to the product from the item. 
      newItem.Products = returnedProduct; 
      svcContext.SetLink(newItem, "Products", returnedProduct); 
     } 
    ); 
} 

내 데이터베이스 스크립트 :이 특정 예제는 다음 코드를 사용하여 3 개 연결된 테이블 (제품, 주문, ORDER_DETAILS)에이 기능을 보여줍니다

CREATE TABLE InmarsatZenith.dbo.ClientJob 
(JobRef nvarchar(15), 
Summary text 
PRIMARY KEY(JobRef)) 

CREATE TABLE InmarsatZenith.dbo.Job 
(IntRef uniqueidentifier, 
JobRef nvarchar(15), 
CopyDeadline datetime, 
PublicationDate datetime, 
Repeat bit, 
BusinessType nvarchar(25), 
Sector nvarchar(30), 
Lang nvarchar(15), 
Format nvarchar(25), 
CreativeRotation nvarchar(50), 
TipinType nvarchar(25), 
Status nvarchar(100) 
PRIMARY KEY(IntRef)) 

CREATE TABLE InmarsatZenith.dbo.Detail 
(IntRef uniqueidentifier, 
Description nvarchar(100), 
Date datetime 
PRIMARY KEY(IntRef)) 

을 사이에 일대 다 관계가있다 클라이언트 작업 및 작업 (1 개의 클라이언트 작업은 많은 작업을 가질 수 있음). 그리고 일과 세부 사항 사이의 일대일 관계.

문제는 내 비동기 메서드를 내 응용 프로그램에 구현하는 것이지만 훨씬 간단한 일대일 관계입니다. 그래서 본질적으로 새로운 "Job"테이블에 새로운 Job을 추가하고 관련 세부 사항을 "Job Details"테이블에 추가 할 수 있기를 원합니다. 이 코드 샘플을이 특정 메서드로 작업하도록 변환하는 데 약간의 문제가 있었으며 일대일 관계에서 작동하도록이 코드를 적용하는 데 도움이 될 것입니다.

누구든지이 주제에 대해 나에게 계몽 할 수 있다면 정말 고마워 할 것입니다.

친절에 대해 감사드립니다.

답변