动程序中设置DateTimeSerializationOptio

动程序中设置DateTimeSerializationOptio

本文介绍了在mongodb C#驱动程序中设置DateTimeSerializationOptions.Defaults的新方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此行设置日期时间默认值.

I was using this line to set the datetime defaults.

DateTimeSerializationOptions.Defaults = DateTimeSerializationOptions.LocalInstance;

我收到此警告."MongoDB.Bson.Serialization.Options.DateTimeSerializationOptions.Defaults"已过时:使用所需选项创建并注册DateTimeSerializer."

但是我找不到改变它的示例...我该如何改变这种绝对用法?

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

推荐答案

像这样注册日期/时间序列化器:

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.

这篇关于在mongodb C#驱动程序中设置DateTimeSerializationOptions.Defaults的新方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 22:42