这里有关于新的WCF Ria服务测试版的快速问题:
如果我在代码隐藏中执行此操作:
EntitySet e = MyContext.Employees
似乎实体集在运行时总是空的?即如果我想循环通过Employee实体集。
另外,如果我获得了实体集的枚举器,我会收到一个错误,告诉我枚举器是空的还是尚未启动。有没有办法从上下文中获取实体集合并迭代它们?
提前致谢!
答案 0 :(得分:5)
您是否在已完成事件回复中进行了检查?请记住,在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;
}