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/