I am evaluating Dapper as a replacement for custom and cumbersome code and so far all was very good and promising. But this morning I have stumbled on a problem with Dynamic parameters and cannot find a solution.
A stored procedure calculates the Account Balance and the Available Balance for a customer returning its result in two decimal output parameters. These decimals are declared in the stored procedure with Precision=18 and Scale=2. This procedure works perfectly with the current standard methods. But in Dapper I cannot find a way to pass these parameters and specify the scale so all I get back is the integer part of the decimal value.
using (IDbConnection connection = OpenConnection())
{
var args = new DynamicParameters(new { custID = customerID});
// No way to set the scale here?
args.Add("@accnt", dbType: DbType.Decimal, direction: ParameterDirection.Output);
args.Add("@avail", dbType: DbType.Decimal, direction: ParameterDirection.Output);
var results = connection.QueryMultiple("Customer_CalcBalance", args, commandType:CommandType.StoredProcedure);
decimal account = args.Get<decimal>("@accnt");
decimal availab = args.Get<decimal>("@avail");
}
And here is the question(s), there is a way to pass the scale for a decimal output parameter? Or there is a different way to accomplish my goal to get back the exact decimal values?
outputparameters aredecimalright? But you want that to come back to you truncated (e.g.101.78becomes101.00)?