OrmLite storing DateTime with ms precision in MySql

By default DateTime persisted to MySql using OrmLight have second precision.

Is there a way to persist DateTime with millisecond precision?


You can change the MySql Column Type used with a [CustomField] attribute to use a MySql DateTime type with fractional seconds precision, e.g. DateTime(fsp).

I’ve just added support for specifying a precision by modifying the DateTime converter, e.g:

if (MySqlDialect.Provider.GetConverter(typeof(DateTime)) 
    is MySqlDateTimeConverterBase dateConverter)
    dateConverter.Precision = 3;

This is now available in the latest v5.10.4 that’s now on NuGet.

You Sir rock. Thanks. The attribute worked well.

1 Like