is there any possibility to include sub entities in my query on the client? I'm working on a Silverlight application using RIA Services, a DomainService and EntityFramework behind it for my database access. In Order to get associated entities when calling the DomainService for data, I have to modify the DomainService' metadata with the [Include] attribute and use the Include() method on the DomainService. (e. g. ObjectContext.Parent.Include("Child"))
However, I feel like ending up with a ton of methods for each entity in my DomainService to get all different combinations of associated data, because sometimes I'll need a user and the associated role, sometimes I only want to get the user without any associated data and so on...
According to some RIA tutorials, it is recommended to use the functionality given by Expression Trees to modify a query on the client side. Is there any way of including on the client instead of the DomainService' get-method? I feel like this must be a common issue when working with DomanServices?!
During my research, I stumbled over a similar question but without any answer and another thread where someone said it is not possible. But that answer was posted around April 开发者_运维百科2009 and there have been a lot of changes in the development since then.
Thanks
You can query method on the server. Let say you have this code on server:
public IQueryable<Employee> GetEmployeesSorted()
{
return from Employee emp in ObjectContext.Employees
orderby emp.Title, emp.HireDate
select emp;
}
you can use like this on client
EmployeeContext context = new EmployeeContext();
EntityQuery<Employee> query =
from emp in context.GetEmployeesSortedQuery()
where emp.SalariedFlag == true
select emp;
Hope this will help.
精彩评论