how to manage _id field when using POCO with mongodb c# driver

后端 未结 5 2060
面向向阳花
面向向阳花 2020-12-14 01:01

If I want to read and write mongo data with a POCO

public class Thingy
{
     public string Foo {get;set;}
}
...
coll.Insert(new Thing(Foo = \"hello\"));
         


        
5条回答
  •  别那么骄傲
    2020-12-14 01:52

    Add a property as follows:

    public BsonObjectId Id { get; set; }
    

    The MongoDB driver automatically converts Id to _id during serialization\deserializtion.

提交回复
热议问题