title: Petapoco issue with nullable SQl Server smallint and int16 in vb.net
body: <p>I have an SQL Server table with a view and a smallint field. All data in the view are automatically marked as nullable from Petapoco T4 generator since you can't specifiy it in a view.
  I'm fine with all the other datatypes so far (guid, int, tinyint, string, etc.) but it seems that the nullable smallint cause some issues.</p>
  
  <p>The T4 generator in VB.NET creates this for the SMALLINT field:</p>
  
  <pre><code>    Private mPasswordResetDays As Integer?
      &lt;Column&gt; _
      Public Property PasswordResetDays() As Integer?
          Get
              Return mPasswordResetDays
          End Get
          Set
              mPasswordResetDays = Value
          End Set
      End Property
  </code></pre>
  
  <p>BUt I receive an exception:</p>
  
  <p>Cast from 'System.Int16' to 'System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' </p>
  
  <p>At Petapoco line 2677:</p>
  
  <pre><code>Line 2675:       else
  Line 2676:       {
  Line 2677:          converter = src =&gt; Convert.ChangeType(src, dstType, null);
  Line 2678:       }
  Line 2679:            }
  </code></pre>
  
  <p>The SQL Command executed from PetaPoco is quite simple:</p>
  
  <pre><code>SQL Command: SELECT UserId, AllowPersistentCookie, MinPasswordLenght,
  NonAlphanumericPasswordChars, AlphanumericPassword, PasswordResetDays FROM
  EVA_vw_UserLoginStatusFromRoles
  WHERE UserId = @0 -&gt; @0 [String] = "d85674ab-d389-4548-ad89-5322892ca0e2"
  </code></pre>
  
  <p>I think a similar issue has been noted on ExecuteScalar command returning null but the line is different and the code too.</p>
  
  <p>If I change the type from Integer? to Integer, making them not nullable, everything works fine.</p>
  
  <p>Any hint on this issue with Petapoco and SQL Server Smallints?</p>
  
  <p>ADDENDUM: the view code is:</p>
  
  <pre><code>SELECT     a.UserId, CAST(MIN(CAST(b.AllowPersistentCookie AS int)) AS bit) AS AllowPersistentCookie, MAX(b.MinPasswordLenght) AS MinPasswordLenght, 
                    CAST(MAX(CAST(b.NonAlphanumericPasswordChars AS int)) AS bit) AS NonAlphanumericPasswordChars, CAST(MAX(CAST(b.AlphanumericPassword AS int)) AS bit) 
                    AS AlphanumericPassword, MIN(b.PasswordResetDays) AS PasswordResetDays
  FROM         dbo.EVA_UsersInRoles AS a INNER JOIN
                    dbo.EVA_Roles AS b ON a.RoleId = b.RoleId
  WHERE       (DATEDIFF(day, CONVERT(date, GETUTCDATE()), a.StartDate) &lt;= 0) AND (DATEDIFF(day, CONVERT(date, GETUTCDATE()), a.EndDate) &gt;= 0) OR
                    (DATEDIFF(day, CONVERT(date, GETUTCDATE()), a.StartDate) &lt;= 0) AND (a.EndDate IS NULL) OR
                    (DATEDIFF(day, CONVERT(date, GETUTCDATE()), a.EndDate) &gt;= 0) AND (a.StartDate IS NULL) OR
                    (a.EndDate IS NULL) AND (a.StartDate IS NULL)
  GROUP BY a.UserId
  </code></pre>