OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
675 stars 348 forks source link

Failure when posting a request with odata-version header equal 4.01 #3009

Open Yglioh opened 1 week ago

Yglioh commented 1 week ago

Hi,

I have a Create endpoint to which I try to send an object, e.g. a user:

public async Task<ActionResult<IQueryable<User>>> Post([FromBody] User entity)
{
    return await TryCatchAsync<User>(async () =>
    {
        await Entities.Add(entity);
        return Created(entity);
    });
}

Payload:

{
    "FirstName": "John",
    "LastName": "Doe",
    "Email": "John.Doe@test.com"
}

When I make this POST request with an odata-version = 4.0 header or without it, the input parameter entity is correctly deserialized. However when I add the header odata-version = 4.01 the object is null. Hence I'm wondering if I'm forgetting something to make this work.

Furthermore I have:

services.AddControllers()
    .AddOData(options => options.AddRouteComponents("", edmModel, ODataVersion.V401, services => { return; }));

The reason I'm asking this is because in a more complex use case I have, I'm using the odata client to post a deep insert request which automatically uses odata-version = 4.01 and a syntax that omits the odata prefix.

Assemblies affected

Target framework: net6.0 Microsoft.AspNetCore.OData 8.2.5 Microsoft.OData.Client 7.21.1