Noda Time Support
Noda Time is an alternative date and time API for .NET. It was written by Jon Skeet to solve many flaws of original .NET api. Since version 4.0 Npgsql supports and suggests it as recommended way of working with Date and Time.
See more in:
Setup
Marten provides Marten.NodaTime plugin. That provides necessary setup.
Install it through the Nuget package.
PM> Install-Package Marten.NodaTime
Then call UseNodaTime()
method in your DocumentStore
setup:
var store = DocumentStore.For(_ =>
{
_.Connection(ConnectionSource.ConnectionString);
// sets up NodaTime handling
_.UseNodaTime();
});
By default it also sets up the JsonNetSerializer
or SystemTextJsonSerializer
options (see more details in NodaTime documentation).
If you're using custom Json serializer or you'd like to maintain fully its configuration then you can set disable default configuration by setting shouldConfigureJsonSerializer
parameter to false
. By changing this setting you need to configure NodaTime Json serialization by yourself.
var store = DocumentStore.For(_ =>
{
_.Connection(ConnectionSource.ConnectionString);
_.Serializer<CustomJsonSerializer>();
// sets up NodaTime handling
_.UseNodaTime(shouldConfigureJsonSerializer: false);
});
WARNING
By using NodaTime plugin - you're opting out of DateTime type handling. Using DateTime in your Document will end up getting NotSupportedException exception.