Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple.OData.Client is unable to invoke Action that accepts entity collection #117

Closed
PrashantDeherkar opened this issue Jun 14, 2015 · 5 comments

Comments

@PrashantDeherkar
Copy link

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();
}
It gives 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? Please help.

@object
Copy link
Member

object commented Jun 15, 2015

Thanks for reporting the issue.

  1. Can you try most recent of Simple.OData.Client? There's been some changes since the version 4.3, so I'd recommend trying 4.7.
  2. If the error still occurs, can you share the service metadata document?

@PrashantDeherkar
Copy link
Author

I have now used Simple.OData.Client v 4.7.1 but getting the same error. The service metadata is as follows: http://localhost:55225/Service/$metadata
(And I have the sample solution but do not know how to post it here (452 KB zip file) )

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="ODataService.Models" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Car">
<Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="Edm.Int32" Nullable="false" />
    <Property Name="Model" Type="Edm.String" />
    <Property Name="Make" Type="Edm.String" />
    <NavigationProperty Name="Wheels" Type="Collection(ODataService.Models.Wheel)" />
  </EntityType>
  <EntityType Name="Wheel">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="Edm.Int32" Nullable="false" />
    <Property Name="Name" Type="Edm.String" />
    <Property Name="Description" Type="Edm.String" />
    <Property Name="PositionEnum" Type="ODataService.Models.Position" Nullable="false" />
  </EntityType>
  <EnumType Name="Position">
    <Member Name="FrontLeft" Value="0" />
    <Member Name="FrontRight" Value="1" />
    <Member Name="RearLeft" Value="2" />
    <Member Name="RearRight" Value="3" />
  </EnumType>
</Schema>
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
  <Action Name="UpdateWheels" IsBound="true">
    <Parameter Name="bindingParameter" Type="Collection(ODataService.Models.Wheel)" />
    <Parameter Name="carId" Type="Edm.Int32" Nullable="false" />
    <Parameter Name="wheels" Type="Collection(ODataService.Models.Wheel)" />
  </Action>
  <EntityContainer Name="Container">
    <EntitySet Name="Cars" EntityType="ODataService.Models.Car">
      <NavigationPropertyBinding Path="Wheels" Target="Wheels" />
    </EntitySet>
    <EntitySet Name="Wheels" EntityType="ODataService.Models.Wheel" />
  </EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

@object
Copy link
Member

object commented Jun 15, 2015

I will appreciate sample solution, it will be easier to reproduce the problem. Can you send it to me at vagif.abilov@gmail.com?

@object
Copy link
Member

object commented Jun 15, 2015

I managed to reproduce the issue. Expect the fix soon :-)

@PrashantDeherkar
Copy link
Author

The new version 4.7.2 has fixed the issue for me. Thanks for prompt support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants