Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using decimal type #261

Closed
clintonvb opened this issue Mar 29, 2015 · 3 comments
Closed

using decimal type #261

clintonvb opened this issue Mar 29, 2015 · 3 comments

Comments

@clintonvb
Copy link

When using a stored procedure in MS-SQL as below, I am unable to get the output as a decimal value using Dapper.

Below are some snippets of the code from my solution

CREATE PROCEDURE dbo.Proc @c decimal(10,5) OUTPUT
var parameters = new DynamicParameters();
parameters.Add("c", dbType: DbType.Decimal, direction: ParameterDirection.Output);

con.Execute("dbo.Proc", parameters, commandType: CommandType.StoredProcedure);
Console.WriteLine("@c \t{0}", (decimal)parameters.Get<Decimal>("c"));

It gets returned as 12, when my proc is hard coded to return 11.884

When I change the DbType from Decimal to Single it returns 11.884. Is there something I am doing wrong with the Decimal implementation?

@mgravell
Copy link
Member

That doesn't sound good. I will investigate.
On 29 Mar 2015 19:33, "clintonvb" notifications@github.com wrote:

When using a stored procedure in MS-SQL as below, I am unable to get the
output as a decimal value using Dapper.

Below are some snippets of the code from my solution

CREATE PROCEDURE dbo.Proc @c decimal(10,5) OUTPUT

var parameters = new DynamicParameters();
parameters.Add("c", dbType: DbType.Decimal, direction: ParameterDirection.Output);
parameters.AddDynamicParams(new { });

con.Execute("dbo.pr_Test", parameters, commandType: CommandType.StoredProcedure);
Console.WriteLine("@c \t{0}", (decimal)parameters.Get("c"));

It gets returned as 12, when my proc is hard coded to return 11.884

When I change the DbType from Decimal to Single it returns 11.884. Is
there something I am doing wrong with the Decimal implementation?


Reply to this email directly or view it on GitHub
#261.

@mgravell
Copy link
Member

This is precision and scale defaulting to bad values (thanks SqlClient); new controls will be available next build. The following now passes:

    public void Issue261_Decimals()
    {
        var parameters = new DynamicParameters();
        parameters.Add("c", dbType: DbType.Decimal, direction: ParameterDirection.Output, precision: 10, scale: 5);
        connection.Execute("create proc #Issue261 @c decimal(10,5) OUTPUT as begin set @c=11.884 end");
        connection.Execute("#Issue261", parameters, commandType: CommandType.StoredProcedure);
        var c = parameters.Get<Decimal>("c");
        c.IsEqualTo(11.884M);
    }

@clintonvb
Copy link
Author

Thank you for the quick turnaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants