bomortensen
bomortensen

Reputation: 3396

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 Employee 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!

Upvotes: 2

Views: 2030

Answers (1)

Martin Hollingsworth
Martin Hollingsworth

Reputation: 7329

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;
}

Upvotes: 5

Related Questions