c# - Dapper How to Handle DBNull by DynamicParameter.Get -


var param = new dynamicparameters(); param.add("msgid", dbtype.int32, direction: parameterdirection.output);  connection.execute(messageseloutmessageid, param, commandtype: commandtype.storedprocedure); count = param.get<int>("msgid"); 

by reference dapper, using code above call stored procedure output parameter - msgid. working fine in cases, there no value found stored procedure , returned output parameter value null. in these cases exception error below :

attempting cast dbnull non nullable type! note out/return parameters not have updated values until data stream completes (after 'foreach' query(..., buffered: false), or after gridreader has been disposed querymultiple)

understood mark return data type nullable avoid error code below

count = param.get<int?>("msgid"); 

but there other way check param.get("msgid") == null instead of using nullable data type - int?

thanks paulius, tried dynamic datatype count = param.get<dynamic>("msgid"); , work i'm looking for.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -