Handling MongoDB's ISODate() when attempting to parse a serialized JSON string

前端 未结 6 1790
庸人自扰
庸人自扰 2021-02-07 11:00

I\'m using MongoDB via the official C# driver with an ASP.NET MVC web site.

I have the following C# model:

public class Contact
{
    public ObjectId Id          


        
6条回答
  •  我在风中等你
    2021-02-07 11:32

    I realize that I am very late to this party but I'll post an answer anyway in case somebody else comes along looking for a solution (as I did).

    The trick is to let the Mongo db driver do the deserialization:

    var collection = database.GetCollection("collection name");
    var contact = collection.Find(Query.EQ("Name", "Joe Blow"));
    

    Now contact will have the expected values.

提交回复
热议问题