DomainService:客户端上的.include()

发布于 2024-10-08 22:30:40 字数 624 浏览 7 评论 0原文

是否有可能在客户端的查询中包含子实体? 我正在开发一个 Silverlight 应用程序,该应用程序使用 RIA 服务、其背后的 DomainService 和 EntityFramework 来进行数据库访问。 为了在调用 DomainService 获取数据时获取关联实体,我必须使用 [Include] 属性修改 DomainService 的元数据,并使用 DomainService 上的 Include() 方法。 (例如 ObjectContext.Parent.Include("Child"))

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

根据一些RIA教程,它是建议使用表达式树提供的功能来修改客户端的查询。 有没有什么方法可以包含在客户端而不是 DomainService 的 get 方法? 我觉得这一定是使用 DomanServices 时的常见问题?!

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2024-10-15 22:30:40

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

public IQueryable<Employee> GetEmployeesSorted()
{
    return from Employee emp in ObjectContext.Employees
    orderby emp.Title, emp.HireDate
    select emp;
}

您可以在客户端上像这样使用

EmployeeContext context = new EmployeeContext();

    EntityQuery<Employee> query =
        from emp in context.GetEmployeesSortedQuery()
        where emp.SalariedFlag == true
        select emp;

希望这会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文