I have the following code in the Silverlight RIA WCF services application:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
EmployeesService2 context = new EmployeesService2();
EntityQuery<Employee> query = context.GetEmployeeQuery();
context.Load(query);
int count = context.Employees.Count();
EmployeeGrid.ItemsSource = context.Employees;
}
It populates Grid with items, but context.Employees.Count() = 0
. Why is this so?
Another problem is that I have a similar code for another page against different domain service which based on another entity model and database. But in that case the service didn't return any entities. What can be possible reason for that? The database is not empty.
This is probably because the context.load is still loading at the moment you are asking for the count of it's items.
try this
var operation = context.Load(query);
operation.Completed += (s,ea) =>
{
int count = operation.Entities.Count();
EmployeeGrid.ItemsSource = operation.Entities.ToList();
}