odata - Simple.OData.Client - 无法调用接受实体集合参数的操作

标签 odata asp.net-web-api2 simple.odata

I get error "The parameter 'wheels' is of Edm type kind 'Collection'. You cannot call CreateCollectionWriter on a parameter that is not of Edm type kind 'Collection'."

以下是我的设置的详细信息:

Web API 2.2 OData v4 服务:我在我的服务中的 WheelsController 类中定义了 Action,如下所示:

public async Task<IHttpActionResult> UpdateWheels(ODataActionParameters   parameters)
{
object value;
parameters.TryGetValue("carId", out value);
int carId= (int)value;
parameters.TryGetValue("wheels", out value)
IEnumerable<Wheel> wheels = (IEnumerable<Wheel>)value;
// logic goes here....
return OK();
}

在WebApiConfig.cs文件中,Action配置定义如下:

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Car>("Cars");
builder.EntitySet<Wheel>("Wheels");
var action = builder.EntityType<Wheel>().Collection.Action("UpdateWheels");
action.Parameter<int>("carId");
action.CollectionParameter<Wheel>("wheels");

我成功地从 FireFox 浏览器中的 RESTClient 扩展调用上述操作 作为对 URL“http://localhost/Service/Wheels/UpdateWheels”的 POST 请求,请求正文为

{"carId":2,
"wheels":[{"Id":1,"Name":"Wheel Front 1","Description":"Front wheel left",   "PositionEnum":"FrontLeft"},
{"Id":2,"Name":"Wheel Front 2","Description":"Front wheel right",   "PositionEnum":"FrontRight"}]
}

但是,当我尝试在客户端应用程序(例如

)中使用 Simple.OData.Client 调用上述服务操作时,它会出现错误
public async void TestUpdateWheels(List<Wheel> wheelList)
{
// client is derived from ODataClient from assembly Simple.OData.Client.Core.dll, v4.3.0.0
await client.For<Wheel>()
.Action("UpdateWheels")
.Set(new { carId = 2, wheels = wheelList})
.ExecuteAsync();
}

Error message: The parameter 'wheels' is of Edm type kind 'Collection'. You cannot call CreateCollectionWriter on a parameter that is not of Edm type kind 'Collection'.

如何从 ODataClient 成功调用上述 Action?

最佳答案

当我向项目站点报告时,这证明是 Simple.OData.Client 版本 4.3.0 中的一个错误。详情请访问链接 https://github.com/object/Simple.OData.Client/issues/117

The new bug fix version 4.7.2 of Simple.OData.Client has fixed the issue for me!

关于odata - Simple.OData.Client - 无法调用接受实体集合参数的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30840347/

相关文章:

xamarin - 简单的 odata FindEntriesAsync 方法不返回集合

asp.net-web-api - 如何使用 asp.net web api 2.2 将 OData v4 端点的引用添加到 mvc 客户端应用程序

javascript - 如何将 `2018911` 这样的字符串格式化为日期?

asp.net-web-api - DocumentDB/CosmosDB 中的 WebAPI OData 和跳过/分页

asp.net-mvc-2 - ASP.NET MVC 的 OData 实现

c# - 在 WebAPI 响应中嵌入其他 API 资源

asp.net-web-api - 默认请求 header 不接受任何值,它始终为空

xamarin - "Unauthorized"Simple.OData.Client 通过使用来自 Xamarin PCL 的有效凭据访问 SharePoint REST API 的异常

entity-framework - 使用 EF 和 WebAPI,如何返回 ViewModel 并支持 IQueryable/OData?