我创建简单的类:
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'。
我做错了什么?