3

This OData function does not deserialize the model parameter from the body. It deserializes as null as seen from response. Is there support for FromBody parameters in OData V4?

ConfigV1.cs

builder.Function("CreateTestModel").Returns<TestModel>();
var edmModel = builder.GetEdmModel()
config.MapODataServiceRoute("ODataRouteV1", "v1", edmModel);

TestController.cs

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Query;
using System.Web.OData.Routing;

public class TestController : ODataController
    [HttpPost]
    [ODataRoute("CreateTestModel")]
    public TestModel CreateTestModel([FromBody]TestModel model)
    {
        return model;
    }
}

TestModel.cs

public class TestModel
{
    public string Value { get; set; }
}

Request

POST /v1/CreateTestModel HTTP/1.1
Host: localhost:8090
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 4810cdc0-d92b-b7b5-4328-8b87e0222854

{
    "Value": "test"
}

Response

{
  "@odata.context":"http://localhost:8090/V1/$metadata#Edm.Null","@odata.null":true
}
Chris Barrett
  • 516
  • 3
  • 12

2 Answers2

1

In V4 we are using ODataActionParameter in the controller method, you can refer to this page to get detail information, and there are more V4 features.

http://odata.github.io/WebApi/#04-07-action-parameter-support

Fan Ouyang
  • 2,132
  • 1
  • 11
  • 13
1

OData Functions should be called with an HTTP GET and shouldn't affect the server. Your method here CreateTestModel sounds like it will affect the server so I would say that it is probably more suited to an OData Action. This may seem like it isn't relevant but I think that it will actually fix your issue as well because Actions are setup to have parameters in the body whereas Functions typically get parameters from the URL

TomDoesCode
  • 3,580
  • 2
  • 18
  • 34