WCF数据服务& EF4 CTP5,如何配置查询的默认预加载模式?
项目: 通过 OData(Wcf 数据服务)公开由代码优先方法配置的实体框架 ObjectContext。
对于简单的查询和 CUD 操作来说一切正常。 但是,我看不到如何配置默认架构加载(服务器端)。
IE:如果我的实体客户有一组地址或与称为经理的实体的一对一关系,如何配置我的 ObjectContext 以便对客户的每个查询都会自动加载客户的所有地址和经理实体?
我知道在客户端,调用者可以使用query().Expand(“path”)
来预先加载数据。但是,我想在服务器端指定它,以便对客户实体的所有查询都会产生 .Include("Addresses")
或 .Include("Manager")< /code> 会默认配置吗?
有什么想法吗?
我们能想到的唯一“黑客”是一个 HTTPModule
,它拦截 GET
请求并向 URL 添加一些 ?expand=XXX
。如果我们找不到更好的东西,这将是我最后的解决方案...
感谢您的帮助!
Project:
Exposing via OData (Wcf Data services) an Entity Framework ObjectContext configured by code-first approach.
Everything works fine for simple queries and CUD operations.
However, I can't see how to configure default schema loading(server side).
IE: If my entity Customer has a collection of Addresses or a one on one relation to an Entity called Manager, how can I configure my ObjectContext so that every queries on Customers would load automatically all the addresses and the manager of the Customers Entities?
I know that on the client-side, the caller can use the query().Expand("path")
to eager load data. But, I want to specify it on the server side so that all queries on Customers entities will result as it was the .Include("Addresses")
or .Include("Manager")
would be configured by default?
Any idea?
The only 'hack' we can think of is an HTTPModule
that intercepts GET
requests and adds some ?expand=XXX
to the URL. This would be my last solution if we cannot find anything better...
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用查询拦截器。
http://msdn.microsoft.com/en-us/library/dd744837.aspx
You could try using a query interceptor.
http://msdn.microsoft.com/en-us/library/dd744837.aspx