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
Everything seems to be going well, except I'm not sure how to handle a MongoDB Null value
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
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."
Can anyone suggest a reference or different approach to handle the nulls? Will BsonString.Empty help me here?
public double? LaborHours { get; set; }
public double? Quantity { get; set; }
Allowed me to pass nulls into those fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With