Find简单实例
Category category=null;
var database = MongoContext.MONGO_CLIENT.GetDatabase("customers");
var collection = database.GetCollection<BsonDocument>("category");
FilterDefinition<BsonDocument> filters = MongoContext.FILTER.Eq("CustomerID", customerID);
BsonDocument bsons = collection.Find(filters).FirstOrDefault();
if (bsons != null)
{
string json = bsons.ToJson();
category = BsonSerializer.Deserialize<Category>(bsons.ToJson());
}
1、ObjectId _id属性反序列化解决方案
[BsonIgnoreExtraElements]
public class Category
{
public Category()
{
_id = ObjectId.GenerateNewId();
}
public ObjectId _id { get; set; }
}
2、DateTime类型的数据序列化时间有时区问题解决方案
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime? TagTime { get; set; }

博客围绕MongoDB和C#展开,介绍了Find简单实例,重点给出了ObjectId _id属性反序列化以及DateTime类型数据序列化时间有时区问题的解决方案,为使用MongoDB和C#进行开发的人员提供了技术参考。
1万+

被折叠的 条评论
为什么被折叠?



