2

新しい WCF Ria サービスのベータ版に関する簡単な質問:

コードビハインドでこれを行う場合:

EntitySet e = MyContext.Employees

実行時にエンティティセットが常に空であるように見えますか? つまり、Employeeエンティティセットをループしたい場合。

また、エンティティセットの列挙子を取得している場合、列挙子が空であるか、まだ開始されていないことを示すエラーが表示されます。コンテキストからエンティティのコレクションを取得し、それらを反復処理する方法はありますか?

前もって感謝します!

4

1 に答える 1

5

Completedイベント コールバック内を確認しましたか? Silverlight 内では、すべての呼び出しが非同期であることを思い出してください。コールバックの前に ItemsSource が割り当てられているサンプル コードが表示されている場合でも、それは Employees がデータ バインディングの 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;
}
于 2009-12-10T21:40:32.237 に答える