如何通过WCF数据服务公开相关数据? [英] How do I expose related data through a WCF Data Service?

查看:121
本文介绍了如何通过WCF数据服务公开相关数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读Alex D. James的3年博客文章,如下所示:

I have been reading through Alex D. James three year old blog posts as found here:

http://blogs.msdn.com/b/alexj/archive/2010/02/24/creating-a-data-service-provider-part-8-relationships.aspx

这是一个关于通过WCF数据服务公开自定义数据的精彩博客系列.在标题为关系"的第八篇文章中,他谈到了如何描述和公开相关数据.一位评论者指出的帖子问题是他在内存中完成了该帖子,但没有说明如何动态提供相关数据.

It is a wonderful blog series about exposing custom data through WCF Data Services. In the 8th post titled "Relationships" he talks about how to describe and expose related data. The problem with the post as pointed out by the one commenter is that he does it in memory, but does not explain how to dynamically supply related data.

以他的示例为例,我想通过数据库动态地获取产品".我该怎么办?

Using his example, I would like to fetch my "Products" dynamically through a database for instance. How do I do that?

推荐答案

您需要编写一个自定义的IQueryable实现. WCF DS服务器将构造一个LINQ查询,该查询描述该查询(包括所有扩展和对所有属性的访问).使用自定义实现,您可以将此类查询转换为所需的任何内容.或者,您可以覆盖查询评估(GetEnumerator和枚举器执行)以从某处检索相关数据.

You would need to write a custom IQueryable implementation. The WCF DS Server will construct a LINQ query which describes the query (including all expansions and accesses to all the properties). With custom implementation you can translate such query to whatever you want. Or you can overwrite the query evaluation (GetEnumerator and enumerator execution) to retrieve the related data from somewhere.

请注意,这绝对不是一件容易的事.我写了一系列有关LINQ表达式树以及每个部分含义的博客文章.您需要至少部分地在代码中识别它们,以实现相关属性的延迟加载. http://blogs.msdn.com/b/vitek/archive/2010/02/25/data-services-expressions-part-1-intro.aspx

Note that this is definitely not a trivial task. I wrote a series of blog posts about the LINQ expression trees which are generated and what each part means. You would need to at least partially recognize these in your code to implement the delay loading of related properties. http://blogs.msdn.com/b/vitek/archive/2010/02/25/data-services-expressions-part-1-intro.aspx

这篇关于如何通过WCF数据服务公开相关数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆