Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 客户端上的DomainService:.Include()_Silverlight_Entity Framework_Ria_Expression Trees_Domainservices - Fatal编程技术网

Silverlight 客户端上的DomainService:.Include()

Silverlight 客户端上的DomainService:.Include(),silverlight,entity-framework,ria,expression-trees,domainservices,Silverlight,Entity Framework,Ria,Expression Trees,Domainservices,是否有可能在我对客户的查询中包含子实体? 我正在使用RIA服务开发一个Silverlight应用程序,RIA服务是一个域服务,它背后的EntityFramework用于我的数据库访问。 为了在调用DomainService获取数据时获得相关实体,我必须使用[Include]属性修改DomainService的元数据,并在DomainService上使用Include()方法。 (例如ObjectContext.Parent.Include(“子”)) 然而,我想为我的DomainService中

是否有可能在我对客户的查询中包含子实体? 我正在使用RIA服务开发一个Silverlight应用程序,RIA服务是一个域服务,它背后的EntityFramework用于我的数据库访问。 为了在调用DomainService获取数据时获得相关实体,我必须使用[Include]属性修改DomainService的元数据,并在DomainService上使用Include()方法。 (例如ObjectContext.Parent.Include(“子”))

然而,我想为我的DomainService中的每个实体使用大量的方法来获取所有不同的关联数据组合,因为有时我需要一个用户和关联的角色,有时我只想获取没有任何关联数据的用户,等等

根据一些RIA教程,建议使用表达式树提供的功能在客户端修改查询。 是否有任何方法可以在客户端而不是DomainService的get方法上包含? 我觉得在使用域名服务时,这一定是一个常见的问题

在我的研究过程中,我偶然发现了一个类似的问题,但没有任何答案,还有另一条线索,有人说这是不可能的。但是这个答案是在2009年4月发布的,从那时起,发展发生了很多变化


谢谢

您可以在服务器上查询方法。假设您在服务器上有以下代码:

public IQueryable<Employee> GetEmployeesSorted()
{
    return from Employee emp in ObjectContext.Employees
    orderby emp.Title, emp.HireDate
    select emp;
}
public IQueryable GetEmployeesSorted()
{
从ObjectContext.Employees中的员工emp返回
由皇帝头衔,皇帝雇佣的命令
选择emp;
}
您可以在客户端上这样使用

EmployeeContext context = new EmployeeContext();

    EntityQuery<Employee> query =
        from emp in context.GetEmployeesSortedQuery()
        where emp.SalariedFlag == true
        select emp;
EmployeeContext=newemployeecontext();
EntityQuery查询=
来自context.GetEmployeesSortedQuery()中的emp
其中emp.SalariedFlag==true
选择emp;

希望这会有所帮助。

谢谢您快速的回答。我知道这一点,但用于连接关联实体的Include()方法仅在DomainService中的ObjectQuery中直接起作用。关键是我不想对DomainService代码做太多更改。如果我能坚持使用生成的代码,并在查询客户端执行所有修改操作,那就最好了。@Christoph-
.Include
的全部目的就是在服务器上加载数据。我认为您应该做的是在调用域服务时接受一系列关联。然后,服务就可以加载了。例如
var empsWithOrders=domainService.GetEmployees(新[]{“订单”,“订单.产品”})
。使用域服务中的扩展方法转换为
。包括
。您可以使用枚举或复杂泛型(我使用后者)使其更安全。好的,因为我不能通过调用客户端直接包含,所以这对我来说似乎是一个很好的解决方法。谢谢你的主意。