我的包裹:
MongoDB.Driver 2.7.3(最新)
MongoDB.Bson 2.7.3(最新)
这是我的课:
public class Details {
public Object _id { get; set; }
public string domain { get; set; }
public string retailerId { get; set; }
public string channelId { get; set; }
}
这是我获得选拔的代码:
var client = new MongoClient(con);
var database = client.GetDatabase("testdb");
var collection = database.GetCollection<Details>("testcollection");
//this doesnt get anything
var details = collection.AsQueryable<Details>();
//this will do the work but its in List
var details = collection.AsQueryable<Details>().ToList();
//Deserialization that wont work
var details = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<Details>(collection);
要成功地将集合值转换为我的类而又不使其成为ToList(),我缺少什么。
PS:Bson Deserializer无法正常工作并出现错误:无法从“ MongoDB.Driver.IMongoCollection”转换为“ MongoDB.Bson.BsonDocument”