0
“反序列化类Class1的Property1属性时发生错误:ReadString只能在CurrentBsonType为String时调用,而不能在CurrentBsonType为ObjectId时调用。CurrentBsonType是字符串,而不是当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
}
我添加了更多的课程信息。 – iefpw 2012-02-28 20:34:54
我试图反序列化到错误的类。 – iefpw 2012-02-29 00:27:14
现在它适合你吗?如果您有任何后续问题,请告知我。 – 2012-02-29 18:11:20