3

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'."

Below are details of my setup:

Web API 2.2 OData v4 service : I have defined Action in WheelsController class in my service like this:

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();
}

In WebApiConfig.cs files, the Action configuration is defined as below:

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");

I get success in invoking the above action from RESTClient extenstion in FireFox browser as POST request to URL "http://localhost/Service/Wheels/UpdateWheels" with Request Body as

{"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"}]
}

However, it gives error when I try to invoke the above service action using Simple.OData.Client in client application such as

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'.

How can I call successfully the above Action from ODataClient?

2 Answers2

1

This turn out to be a bug in Simple.OData.Client version 4.3.0 when I reported to the project site. For details, visit the link 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!

Community
  • 1
  • 1
0

Try out in this way. It works for me in one of my project.

public async Task<string> TestUpdateWheels(List<Wheel> wheelList)
{
    string getRules = await client.ExecuteActionAsScalarAsync<string>
     ("UpdateWheels", new Dictionary<string, object>
        {
           { "YourParamater", wheelList}

        });
   return getRules ;
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Sam
  • 97
  • 1
  • 3
  • 11
  • Thanks for posting! I have tried exactly what you mentioned. However this is also failing with same error message. – Prashant Deherkar Jun 15 '15 at 11:34
  • You need to put attribute on service action [HttpPost] [ODataRoute("TestUpdateWheels")] [ActionName("TestUpdateWheels")] public IHttpActionResult TestUpdateWheels(){} – Sam Jun 15 '15 at 11:50
  • As I have written, I am able to invoke the Action from Browser RESTClient but not from Simple.OData.Client app. I have [HttpPOST] attribute already applied to the Action method. As it is bound action, the route attribute is not required to be applied. – Prashant Deherkar Jun 15 '15 at 17:08
  • Visit the link for details: https://github.com/object/Simple.OData.Client/issues/117 – Prashant Deherkar Jun 16 '15 at 08:32