title: Dapper How to Handle DBNull by DynamicParameter.Get
body: <pre><code>var param = new DynamicParameters();
  param.Add("MsgId", DbType.Int32, direction: ParameterDirection.Output);
  
  connection.Execute(MessageSelOutMessageId, param, commandType: CommandType.StoredProcedure);
  count = param.Get&lt;int&gt;("MsgId");
  </code></pre>
  
  <p>By referencing Dapper, I used the code above to call a Stored Procedure with an output parameter - MsgId. It is working fine, but in some cases, there would be no value returned from the Stored Procedure and the returned output parameter value would be null. In these cases, I got this exception :</p>
  
  <blockquote>
    <p>Attempting to cast a DBNull to a non nullable type! Note that out/return parameters will not have updated values until the data stream completes (after the 'foreach' for Query(..., buffered: false), or after the GridReader has been disposed for QueryMultiple)</p>
  </blockquote>
  
  <p>I'd understood that we could mark the return Data Type as nullable to avoid this error by using the code below </p>
  
  <pre><code>count = param.Get&lt;int?&gt;("MsgId");
  </code></pre>
  
  <p>But, is there any other way to check <strong>param.Get("MsgId")</strong> == null instead of using nullable data type - <strong>int?</strong></p>