I am using NodaTime as DateTime-API in my AspNetCore OData - webapp. Everything works as expected until serialization. This is my entityBase.
public class DbEntity
{
public Instant CreateDate { get; set; }
}
Here is my Startup-ConfigureServices Method:
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(options => options.SerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
services.AddDbContext<DefaultContext>(
options => options
.UseLazyLoadingProxies()
.UseNpgsql(Configuration.GetConnectionString("someString"), o => o.UseNodaTime()));
services.AddTransient<ICrudEditable, CrudEditable>();
services.AddOData();
I am using Microsoft.AspNetCore.OData 7.0.1 NodaTime 2.4.0 Version together with NodaTime.Serialization.JsonNet 2.0.0 and Newtonsoft.Json 11.0.2.
Actions:
// GET api/values
[HttpGet]
public ActionResult Get ( )
{
return Ok(new DbEntity { CreateDate = SystemClock.Instance.GetCurrentInstant() });
}
Everything fine so far. It´s an action from the default Values controller (derived from ControllerBase). But if I call below action, where Controller derives from ODataController, CreateDate is empty:
[EnableQuery]
[ODataRoute("entity")]
public IActionResult Get()
{
return Ok(new DbEntity { CreateDate = SystemClock.Instance.GetCurrentInstant() });
}
No error, no nothing, just empty..
EDIT I´ve raised an issue on github, for anyone interested on that issue: https://github.com/OData/WebApi/issues/1626