问题
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