MongoDb:无法从BsonType'Int32'反序列化'ObjectId'

时间:2018-01-18 20:54:44

标签: c# mongodb bson int32

我创建简单的类:

 public class User
{       
  //  [BsonRepresentation(BsonType.ObjectId)]
    public ObjectId _id { get; set; }

    [BsonRepresentation(BsonType.String)]
    public String Name { get; set; }

    [BsonRepresentation(BsonType.String)]
    public string Email { get; set; }
}

然后我尝试获取用户集合:

  using (var cursor = await col.Find<User>(Builders<User>.Filter.Empty).ToCursorAsync())
            {
                while (cursor.MoveNext())
                {
                   //do work
                }
            }

因此,它引发了异常:“无法在”ToCursorAsync()“行中从BsonType'Int32'反序列化'ObjectId'。

我做错了什么?

0 个答案:

没有答案