Using decimal with specific precision as output parameters with Dapper

前端 未结 3 855
轮回少年
轮回少年 2021-01-13 08:27

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

3条回答
  •  一生所求
    2021-01-13 09:09

    Well, seems that there is no way to resolve this problem (at least none has found a tentative answer) so I put this workaround that I have implemented to continue with the rest of the work.

    var args = new DynamicParameters(new { custID = customerID});
    args.Add("@accnt", dbType: DbType.Single, direction: ParameterDirection.Output);
    args.Add("@avail", dbType: DbType.Single, direction: ParameterDirection.Output);
    
    var results = connection.QueryMultiple("Customer_CalcBalance", args, commandType:CommandType.StoredProcedure);
    decimal account = args.Get("@accnt");
    decimal availab = args.Get("@avail");
    

    I have passed the output parameters as Single instead of the expected type Decimal.
    In this way, I suppose the SqlParameter.Scale property is set to something different than zero and I could get the decimals digits when I try to read the output parameters.
    If someone has a better solution let me know.

提交回复
热议问题