[英]c# and mongoDB - Cannot deserialize from BsonType Null
I'm new to MongoDB and I've been religiously slogging through the Beginners' guide to using MongoDB 2.2 and the official C# driver http://www.codeproject.com/Articles/524602/Beginners-guide-to-using-MongoDB-and-the-offic 我是MongoDB的新手,我一直在虔诚地搜寻着使用MongoDB 2.2的初学者指南和官方C#驱动程序http://www.codeproject.com/Articles/524602/Beginners-guide-to-using-MongoDB -和最OFFIC
Everything seems to be going well, except I'm not sure how to handle a MongoDB Null value 一切似乎都进行得很好,但我不确定如何处理MongoDB Null值
This is my data structure 这是我的数据结构
public class DataStructure
{
public ObjectId _id { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime UpdatedOn { get; set; }
public string ClaimId { get; set; }
public string Status { get; set; }
public string FmcCity { get; set; }
public string FmcState { get; set; }
public Int32 TestType { get; set; }
public List<LineItemStructure> LineItems { get; set; }
}
public class LineItemStructure
{
public string LineItemDescription { get; set; }
public string LineItemType { get; set; }
public string PartNumber { get; set; }
public double LaborHours { get; set; }
public double Quantity { get; set; }
}
And this is the code which connects to the MongoDB and pulls back values, until it encounters a null field value and returns the error below 这是连接到MongoDB并拉回值的代码,直到遇到空字段值并返回以下错误
var client = new MongoClient(connectionString);
MongoServer server = client.GetServer();
var database = server.GetDatabase("FleetClaims");
MongoCollection< DataStructure> collection = database.GetCollection< DataStructure >("Claims");
//Execute the query
MongoCursor< DataStructure> results = collection.FindAll();
"An error occurred while deserializing the LineItems property of class ...: An error occurred while deserializing the LaborHours property of class ... : Cannot deserialize Double from BsonType Null."
“反序列化类...的LineItems属性时发生错误:反序列化类...的LaborHours属性时发生错误:无法从BsonType Null反序列化Double。”
Can anyone suggest a reference or different approach to handle the nulls? 谁能建议参考或其他方法来处理空值? Will BsonString.Empty help me here?
BsonString.Empty可以在这里帮助我吗?
public double? LaborHours { get; set; }
public double? Quantity { get; set; }
Allowed me to pass nulls into those fields. 请允许我将空值传递到这些字段中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.