title: Reading null into a nullable int with MongoDB C# driver
body: <p>I have data in my MongoDB where I am storing a nullable int, most often as null. My model on the C# side has the variable as <code>int? MaterialID</code>.</p>
  
  <p>When I run <code>.Query.FirstOrDefault()</code>, I get an error "Input string was not in a correct format." whenever it tries to read the null value from Mongo (ints work fine).</p>
  
  <p>I managed to get around this by changing my int? to a string and then later casting that back to an int?, but that's a horrible hack that I really don't like. Anyone have any ideas as to how I can read null from Mongo into my int? on the C# side?</p>
  
  <p>Thanks.</p>
  
  <p>My JSON:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> "Collection" : {
          "List" : [ 
              {
                  "ID" : "40",
                  "StartDate" : ISODate("2013-01-01T00:00:00.000Z"),
                  "EndDate" : ISODate("2013-12-31T00:00:00.000Z"),
                  "MaterialID" : "3"
              }, 
              {
                  "ID" : "40",
                  "StartDate" : ISODate("2014-01-01T00:00:00.000Z"),
                  "EndDate" : ISODate("2014-09-30T00:00:00.000Z"),
                  "MaterialID" : "null"
              }
          ]</code></pre>
  </div>
  </div>
  </p>