返回子元素在ASP.NET的WebAPI的OData [英] Returning child elements in ASP.NET WebAPI OData

查看:232
本文介绍了返回子元素在ASP.NET的WebAPI的OData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的ASP.Net的WebAPI每日构建(日期为2013年1月16日)。

I'm using the latest ASP.Net WebAPI Nightly builds (dated 2013-01-16).

我在那有两个实体的那一刻简单的EF数据库第一款车型 - 患者和访问。每个病人可以有很多访问。

I have a simple EF database first model at the moment that has two entities - Patients and Visits. Each patient can have many visits.

我希望能够查询我的病人名单,并为每个病人的访问返回的实体内联。我知道的WebAPI的OData的实施还不支持扩展$。我希望,只是意味着可选的客户端控制的扩展,不支持,而且我可以强制扩展服务器端。

I'd like to be able to query for my list of patients and have the visits entities for each patient returned inline. I know that WebAPI's OData implementation doesn't yet support $expand. I'm hoping that just means that optional client-controlled expansion is not supported and that I can force expansion server-side.

目前,我没有得到任何的访问内嵌的。

At the moment I'm not getting any of the visits inline.

例如,我的PatientController的()获取()方法看起来像

For example, my PatientController's() Get() method looks like

[Queryable(AllowedQueryOptions=AllowedQueryOptions.Supported)]
public override IQueryable<Patient> Get()
{
    var query = this.entities.Patients.Include("Visits");
    return query;  
}

我已经验证了我对数据库执行查询确实包括访问信息。

I've verified that the query executing against my database does indeed include the visit information.

要使用公开可用的OData服务为例,如果在 HTTP使用的服务://services.odata .ORG /的OData / OData.svc / ,则可以得到供应商的名单。这是<一个href=\"http://services.odata.org/OData/OData.svc/Suppliers\">http://http://services.odata.org/OData/OData.svc/Suppliers.
您也可以要求供应商的名单,其中包括使用产品列表<一个href=\"http://services.odata.org/OData/OData.svc/Suppliers?%24expand=Products\">http://http://services.odata.org/OData/OData.svc/Suppliers?$expand=Products

To use a publicly available OData service as an example, if you use the service at http://services.odata.org/OData/OData.svc/, you can get a list of Suppliers. This is http://http://services.odata.org/OData/OData.svc/Suppliers. You can also ask for a list of suppliers that includes the list of products using http://http://services.odata.org/OData/OData.svc/Suppliers?$expand=Products

通过ASP.NET code步进(通过符号服务器),我已经到了System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer,可以看到它的CreatePropertyBag方法,它建立了要序列化的属性列表,只是不包括导航属性,而且他们似乎并不被被写出为NavigationLinks其他地方列举分开。

Stepping through the ASP.NET code (via the symbols server) I've got to the System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer and can see that it's CreatePropertyBag method, which builds up the list of properties to be serialized, just doesn't include the navigation properties, and they don't seem to be enumerated anywhere else apart from being written out as NavigationLinks.

我是很新的,一般的ASP.NET的世界,花了一个星期左右得到我的头周围事情的工作(的方式特别是到OData的提出在2012年年底和迄今所取得的变化进一步修改在2013年)。

I'm quite new to the ASP.NET world in general and have spent a week or so getting my head around the way things work (particularly with the changes made to OData at the end of 2012 and further changes made so far in 2013).

我怀疑,如果ODataEntityTypeSerializer是被修改(我很高兴地尝试)嵌入在适当的位置这些额外的信息(每个导航链接作为一个嵌套内联饲料尽我可以告诉内),那么我会进行设置。

I suspect that if the ODataEntityTypeSerializer was to be modified (I'm happy to try) to embed this extra information in the appropriate spot (within each navigation link as an nested inline feed as best I can tell) then I'd be set.

问题:


  1. 我是否忽略了一些明显的,有一个标志,我可以设置打开这种行为?我明白为什么,如果这样的标志存在,它会默认为关闭(EF延迟加载和这个标志将不会得到很好)

  1. Have I overlooked something obvious and there's a flag I can set to turn on this behaviour? I can see why, if such a flag exists, it would be off by default (EF lazy loading and this flag wouldn't get on well)

如果#1没有,有一些其他ODataEntityTypeSerializer,我可以用?如果是这样,我怎么转呢?

If #1 is no, is there some other ODataEntityTypeSerializer that I could use? If so, how do I switch to it?

如果#2是没有,因为在那里我应该开始写我自己的任何指针?有没有我可以在我自己的序列代替或我要保持我自己的ASP.NET的扩展项目叉的地方(相对于运行系统项目)

If #2 is no, any pointers for where I should start writing my own? Is there a place I can substitute in my own serializer or do I have to maintain my own fork of ASP.NET's Extensions project (as opposed to the Runtime project)

非常感谢!

推荐答案

$拓展是我们的事情OData的支持列表上非常高。但据我所知,我们没有任何标志来打开它的服务器端。格式化目前不允许你要么替换你自己的序列化。所以,恐怕你在此期间唯一的选择是创建一个叉,并添加支持$扩展。如果你能得到它的工作,请考虑派遣一个拉要求我们的方式:

$expand is very high on our list of things to support for OData. But as far as I know, we don't have any flag to turn it on server-side. The formatter doesn't currently allow you to substitute your own serializers either. So I'm afraid your only option in the meantime is to create a fork and add support for $expand. If you manage to get it working, please consider sending a pull request our way:

的http://aspnetwebstack.$c$cplex.com/SourceControl/network

这篇关于返回子元素在ASP.NET的WebAPI的OData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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