views:

637

answers:

1

Hi all,

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!

+2  A: 

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;
}
Martin Hollingsworth
Hi Martin, sorry for the delayed comment here.Even though I'm using the completed event, it dosn't fire at all. It just skips the loadOperation.Completed and stops there. Shouldn't I be able to step into the completed method?Thanks again :)
bomortensen
I'd set a seperate break point in the completed event handler as "stepping" into it doesn't make sense when it is asynchronous. Provided you hit the break point you can then check the LoadOperation.HasError property and LoadOperation.Error if set.
Martin Hollingsworth