Petapoco issue with nullable SQl Server smallint and int16 in vb.net -


i have sql server table view , smallint field. data in view automatically marked nullable petapoco t4 generator since can't specifiy in view. i'm fine other datatypes far (guid, int, tinyint, string, etc.) seems nullable smallint cause issues.

the t4 generator in vb.net creates smallint field:

    private mpasswordresetdays integer?     <column> _     public property passwordresetdays() integer?                     return mpasswordresetdays         end         set             mpasswordresetdays = value         end set     end property 

but receive exception:

cast 'system.int16' 'system.nullable`1[[system.int32, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]]'

at petapoco line 2677:

line 2675:       else line 2676:       { line 2677:          converter = src => convert.changetype(src, dsttype, null); line 2678:       } line 2679:            } 

the sql command executed petapoco quite simple:

sql command: select userid, allowpersistentcookie, minpasswordlenght, nonalphanumericpasswordchars, alphanumericpassword, passwordresetdays eva_vw_userloginstatusfromroles userid = @0 -> @0 [string] = "d85674ab-d389-4548-ad89-5322892ca0e2" 

i think similar issue has been noted on executescalar command returning null line different , code too.

if change type integer? integer, making them not nullable, works fine.

any hint on issue petapoco , sql server smallints?

addendum: view code is:

select     a.userid, cast(min(cast(b.allowpersistentcookie int)) bit) allowpersistentcookie, max(b.minpasswordlenght) minpasswordlenght,                    cast(max(cast(b.nonalphanumericpasswordchars int)) bit) nonalphanumericpasswordchars, cast(max(cast(b.alphanumericpassword int)) bit)                    alphanumericpassword, min(b.passwordresetdays) passwordresetdays         dbo.eva_usersinroles inner join                   dbo.eva_roles b on a.roleid = b.roleid       (datediff(day, convert(date, getutcdate()), a.startdate) <= 0) , (datediff(day, convert(date, getutcdate()), a.enddate) >= 0) or                   (datediff(day, convert(date, getutcdate()), a.startdate) <= 0) , (a.enddate null) or                   (datediff(day, convert(date, getutcdate()), a.enddate) >= 0) , (a.startdate null) or                   (a.enddate null) , (a.startdate null) group a.userid 

issue plus solution @ https://github.com/toptensoftware/petapoco/issues/153

petapoco needs patching with:

- converter = delegate(object src) { return convert.changetype(src, dsttype, null); }; + var underlyingtype = nullable.getunderlyingtype(dsttype) ?? dsttype; + converter = src => convert.changetype(src, underlyingtype, null); 

views red herring; can reproduce on concrete table returning int null column uint? or similar.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -