开发者

WCF RIA Services, EntitySet always empty?

A quick question here about the new WCF Ria services beta:

If I do this in code-behind:

EntitySet e = MyContext.Employees

It seems that the entityset is always empty at runtime? I.e. if I want to loop through the Emp开发者_如何学Cloyee entityset.

Also, if I'm getting the Enumerator for the entityset, I'll get an error telling me that the enumerator either is empty or hasn't started yet. Is there any way at all to grab a collection of entities from the context and iterate through them?

Thanks in advance!


Have you checked within the Completed event call back? Remember that within Silverlight all the calls are asynchronous. Even if you see sample code where the ItemsSource is assigned before the call back, it is relying to the fact that Employees is an ObservableCollection for the data binding.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜