How is the Get method used with DynamicParameters?

c# dapper

Question

I am trying to run a test to see if I loaded a DynamicParameters object correctly. However, I cannot figure out what the Type is that I should use. I get exceptions when I try to use C#/.NET types (int, string, etc.). I tried to use SqlDbType, but that didn't work. I looked at source and I see that the value is stored as a IDbDataParameter and then cast to the type. Obviously, the types I'm trying don't cast. The data I'm testing with are int. How can I get the values?

var dbParams = new DynamicParameters();
dbParams.Add( "Field1", 1 );
var value = dbParams.Get<int>( "Field1" ); // throws an exception

Expert Answer

The code only expected Get<T> to be used after the SQL had been invoked, in order to obtain the updated value of ref, out and return parameters. Consequently it attempted to de-reference something that didn't exist yet. This will be fixed in the next release (it is fixed in the trunk now).




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why