Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Noda Time Instance value not deserializing correctly

I'm currently using RavenDB to store a object that uses Noda Time's Instant class to store dates.

RavenDb stores the value as

"ArrivalTime": { "Ticks": 13507658019037497 },

but when query the object it is always null and starts at the beginning of unix epoch time.

I have tried using the JsonConvert attribute, but the reader always returns a null value for the Instant type. Also if I use more than one attribute, it only refers to the first.

Should I be using noda time with RavenDb or just stick to regular datetime?

thanks

like image 313
lai tang Avatar asked Nov 04 '22 13:11

lai tang


1 Answers

Using RavenDB 2.5

If you are able to use RavenDB 2.5, then you can have full Noda Time support and use Noda Time types in your domain entities. You will need the Noda Time extensions for RavenDB.

Using RavenDB 2.0

You are probably better off not using Noda Time in your domain entities. Instead, use the built-in types such as DateTimeOffset, DateTime and TimeSpan.

You can use Noda Time in your application logic, but not in the persistence layer. The Instant.ToDateTimeOffset() and Instant.FromDateTimeOffset() methods in Noda Time are very useful, and RavenDB works pretty good with DateTimeOffset values. It stores them in ISO8601 format, and properly converts to UTC time during indexing. This means that you can query an index of DateTimeOffset values without regard to offset conversion.

like image 136
Matt Johnson-Pint Avatar answered Nov 17 '22 22:11

Matt Johnson-Pint