I have created ASP.NET WebAPI
with OData
support.
The Project class has a field named ProjectType
with nullable integer type declaration:
public class Project
{
public string Id { get; set; }
public string Name { get; set; }
public int? ProjectType { get; set; }
}
My WebAPI Controller:
public class LocalModelsController : ODataController
{
public IHttpActionResult Patch([FromODataUri] string key, Delta<Project> patch)
{
var projectUpdated = patch.GetEntity();
var projectType = projectUpdated.ProjectType;
//projectType is null here
}
}
When I send the PATCH http request (with BSON
content type format) from client to WebAPI, the Project object has correct values of Id and Name, but ProjectType is always null.
But when I change the type of ProjectType
field type from int?
to double?
, it works correct:
public double? ProjectType { get; set; }
Is it a limitation of ODATA or I were missing something?
I have worked it out. It is just because I was using BSON
format to transfer objects throught HTTP request. It works well if I use JSON
instead. Not sure what wrong with BSON
format though.