Created
November 21, 2010 02:30
-
-
Save rstam/708380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MongoDB.Bson; | |
using MongoDB.Bson.DefaultSerializer; | |
using MongoDB.Bson.Serialization; | |
using MongoDB.Driver; | |
namespace ConsoleApplication1 { | |
public class Model { | |
public DateTime DateTimeProperty { get; set; } | |
} | |
public static class Program { | |
public static void Main(string[] args) { | |
var server = MongoServer.Create(); | |
var database = server["test"]; | |
var collection = database["test"]; | |
collection.RemoveAll(); | |
var localTime = new DateTimeSerializationOptions { Kind = DateTimeKind.Local }; | |
BsonClassMap.RegisterClassMap<Model>(cm => { | |
cm.MapProperty(c => c.DateTimeProperty) | |
.SetSerializationOptions(localTime); | |
}); | |
var m1 = new Model { DateTimeProperty = DateTime.Now }; | |
var bson = m1.ToBson(); | |
var m2 = BsonSerializer.Deserialize<Model>(bson); | |
var document = BsonSerializer.Deserialize<BsonDocument>(bson); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment