2009-12-10 66 views
2

這裏說一下新的WCF RIA服務測試一個簡單的問題:WCF RIA服務,EntitySet總是空的?

如果我這樣做,在後臺代碼:

EntitySet的E = MyContext.Employees

看來,EntitySet的始終是空的運行?即如果我想遍歷Employee實體集。

而且,如果我得到枚舉的EntitySet的,我會得到一個錯誤,告訴我,無論普查員爲空或尚未開始。有沒有什麼辦法可以從上下文中獲取一組實體並遍歷它們?

在此先感謝!

回答

5

有你的完成事件回調過程中進行檢查?請記住,在Silverlight中,所有的調用都是異步的。即使你看到的是的ItemsSource呼叫之前分配回的示例代碼,它是依靠這樣的事實,員工是數據綁定一個ObservableCollection。

LoadEmployeeCommand() 
{ 
    // The Load method initiates the call to the server 
    LoadOperation<Employee> loadOperation = domainContext.Load(domainContext.GetEmployeesQuery()); 
    // The EntitySet is still empty at this point 
    employeeDataGrid.ItemsSource = domainContext.Employees; 
    loadOperation.Completed += EmployeeLoadOperationCompleted; 
} 

private void EmployeeLoadOperationCompleted(object sender, EventArgs e) 
{ 
    // Don't need to reassign now but at this point the collection should be populated 
    employeeDataGrid.ItemsSource = domainContext.Employees; 
} 
+0

馬丁你好,對不起,這裏的延遲評論。 即使我使用的是完成的事件,它不到風度火的。它只是跳過loadOperation.Completed並停在那裏。我不應該能夠進入完整的方法嗎? 再次感謝:) – bomortensen 2009-12-11 22:49:09

+0

我會設置在完成事件處理一個單獨的斷點爲「加強」到它沒有任何意義,當它是異步的。如果你點擊了斷點,你可以檢查LoadOperation.HasError屬性和LoadOperation.Error(如果設置)。 – 2009-12-12 02:04:33