views:

406

answers:

1

I have a problem when using LINQ to set a where clause on a query in a domain service call.

If I don't set a where clause it works just fine and I get my result back in my completed event (I have only implemented the eventhandler for the completed event to demonstrate my issue here).

LoadOperation<User> load = 
  _Context.Load(_Context.GetUsersQuery());
load.Completed += (se, ea) => 
  MyList.ItemsSource = load.Entities.FirstOrDefault();

If I put a where clause on the query I simply get an empty list. And the where clause should return 1 row :)

LoadOperation<User> load = 
  _Context.Load(_Context.GetUsersQuery().Where(f => f.UserID == UserID));
load.Completed += (se, ea) => 
  MyList.ItemsSource = load.Entities.FirstOrDefault();

Any feedback would be appreciated!

+1  A: 

AFAIK I don't believe it is possible to put the where clause on RIA Services queries like that. You need to implement a method in your service that takes the UserID and puts the where clause on the query in the service.

Here is an example from Brad Abram's blog series on the subject:

public IQueryable<SuperEmployee> GetSuperEmployee(int employeeID)
{
    return Context.GetEmployees().ToList()
          .Where(emp => emp.EmployeeID == employeeID).AsQueryable();

}
Bryant