WCF RIA服务,EntitySet总是空的?

bom*_*sen 2 c# silverlight wcf ria

这里有一个关于新的WCF Ria服务测试版的快速问题:

如果我在代码隐藏中执行此操作:

EntitySet e = MyContext.Employees

似乎实体集在运行时总是空的?即如果我想循环通过Employee实体集.

此外,如果我正在获取实体集的枚举器,我将收到一个错误,告诉我枚举器是空的还是尚未启动.有没有办法从上下文中获取实体集合并迭代它们?

提前致谢!

Mar*_*rth 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;
}
Run Code Online (Sandbox Code Playgroud)