I am Using Dapper for some time now and its a great ORM mapper. but recently i found an issue with decimals being passed as an Output parameter for the Stored procedures would cut off the precision and only returns the whole number.
var dynamicParam = new DynmaicParam();
dynamicParam.Add("decimalOut",11.25,dbtype.decimal,ParameterDirection.OutPut);
connection.execute("sp1",dynamicParam,commandType.StoredProcedures);
decimal val = dynamicParam.Get<decimal>("decimalOut");
in this case val will be 11 its not returning 11.25 as it is meant to when the procedure just returns the exact out put parameter as it was passed.
we have used a work around as following where it returns the precision as well,
var dynamicParam = new DynmaicParam();
dynamicParam.Add("decimalOut",11.25,dbtype.double,ParameterDirection.OutPut);
connection.execute("sp1",dynamicParam,commandType.StoredProcedures);
decimal val = dynamicParam.Get<dynamic>("decimalOut");
but i still think there must be a better way to handle these decimal precision problem in dapper given the fact it's an amazing ORM mapper where it supports in many data types. appreciate a better work around and thanks in Advance
You need to use precision and scale.
Example:
dynamicParam.Add("decimalOut",11.25,dbtype.decimal,ParameterDirection.OutPut, precision: 18, scale: 2);