What is new way of setting DateTimeSerializationOptions.Defaults in mongodb c# driver?

一笑奈何 提交于 2021-02-08 15:50:53

问题


I was using this line to set the datetime defaults.

DateTimeSerializationOptions.Defaults = DateTimeSerializationOptions.LocalInstance;

I get this warning. 'MongoDB.Bson.Serialization.Options.DateTimeSerializationOptions.Defaults' is obsolete: 'Create and register a DateTimeSerializer with the desired options instead.'

But i couldn't find an example to change it... how can I change this obsolute usage?


回答1:


Register the date/time serializer like this:

BsonSerializer.RegisterSerializer(typeof(DateTime), DateTimeSerializer.LocalInstance);

Note that you can't register a serializer once one has already been registered. Also, the driver creates a default serializer for each type the first time it needs one. So you need to call this code before you make your first call to the driver to read or write data.



来源:https://stackoverflow.com/questions/16185262/what-is-new-way-of-setting-datetimeserializationoptions-defaults-in-mongodb-c-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!