I'm using Microsoft.AspNetCore.Odata 7.3 in Asp.net Web Api Core 3.1 project.
It turns out that the lib adds TimeZone of the server to DateTimes from Ef output.
Ef itself returns data with DateTimeKind.Unspecified.
So I expected the odata lib just to omit the TimeZone shift because webApi services behave this way.
The question is how to make odata not to add TimeZone of the server or return everything in utc(Z-format).
Tried to set it via NewtonSoft serializerSettings, but it doesn't work for OData endpoints
services.AddOData();
services.AddMvc(options => {options.EnableEndpointRouting = false;});
services
.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
});
Thanks for help!
Upd: Setting DateTimeKind to Utc on Ef level(via ValueConverters) allows server to convert datetime correctly to local.
But still the datetime is returned not in Z-format but with local TimeZone of server.