【发布时间】:2012-03-18 07:29:59
【问题描述】:
“反序列化Class1类的Property1属性时出错:ReadString只能在CurrentBsonType为String时调用,当CurrentBsonType为ObjectId时不能调用。”
我将 bsonid 放在类的字符串 guid 上并映射类并对其进行序列化,但是当我尝试将对象从 bsondocument 反序列化回类时,它给了我这个错误。
我应该如何解决这个问题?
public class Class1
{
[BsonId]
public string ClassGuid { get; private set; }
}
然后映射类:
if (!BsonClassMap.IsClassMapRegistered(typeof(WordOntology)))
{
BsonClassMap.RegisterClassMap<WordOntology>();
}
然后反序列化
MongoCursor<Class1> _returnResults = _collection.FindAs<Class1>(_query);
然后循环:
foreach(BsonDocument _document in _returnResults)
{
//exception here
}
【问题讨论】:
标签: mongodb mongodb-.net-driver