我有一个webapi控制器,它返回一个Item对象,如:
<Items>
<Item>
<Color>PINK</Color>
<CommercialProductBundle>NOTAPPLICABLE</CommercialProductBundle>
<Descriptions/>
</Item>
<Item>
<Color>Black</Color>
<CommercialProductBundle>NOTAPPLICABLE</CommercialProductBundle>
<Descriptions/>
</Item>
</Items>为了使用ODATA查询功能,我将返回类型改为
公共项目GetAllItems()
项目的“列表”到
IQueryable GetAllItems() .
但我的回应却是:
<ArrayOfItem xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Item>
<Color>PINK</Color>
<CommercialProductBundle>NOTAPPLICABLE</CommercialProductBundle>
<Descriptions/>
</Item>
<Item>
<Color>Black</Color>
<CommercialProductBundle>NOTAPPLICABLE</CommercialProductBundle>
<Descriptions/>
</Item>
</ArrayOfItem>有没有办法摆脱'ArrayOf',再次显示初始的xml?
谢谢你的帮助。
发布于 2014-12-17 04:05:12
您是否让您的控制器从ODataController派生?您是否安装了ASP.NET Web V1-3程序集?您是否修改了WebApiConfig.cs以映射OData路由?
由于OData的可查询性取决于其独特的路由约定和Web配置,因此您可能希望遵循本教程对http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/creating-an-odata-endpoint进行相应的实现以获得此可查询性。
https://stackoverflow.com/questions/27446100
复制相似问题