The decimal output parameter is rounded to the nearest integer in EF5.0.

We use an existing database stored procedure, similar to the one below, which returns decimal output,

CREATE PROCEDURE spTest(@a int, @b decimal(18,2) output) as BEGIN SELECT @b=23.22 SELECT * FROM <TABLE> where id = @a END 

When I call a stored procedure in a C # application (code below), I get the result for the output parameter as 23 instead of 23.22

 ObjectParameter b = new ObjectParameter("b", typeof(System.Decimal)) var result = myentities.context.spTest(1234, b) 

This is the exact same issue posted by Imre Horvath ( http://social.msdn.microsoft.com/Forums/en-US/14bdde82-c084-44dd-ad83-c1305cb966d2/decimal-output-parameter-rounded-to-integer ) , but the difference is that we use SQL Server 2008 and the essence of framework 5.0. After reading the sentence from my post, I opened the edmx file in the xml editor and noticed the following for the @b output parameter, as shown below,

 <Parameter Name="b" Type="decimal" Mode="InOut"/>; 

I changed it to

 <Parameter Name="b" Type="decimal" Mode="InOut" Precision="18" Scale="2"/>; 

and run the application and I got the result as expected (23.22)

This is work, but not a solution, because you know that changes will be lost when updating the stored procedure in the design of the entity framework. There is a lot of stored procedure in our database that has decimal (18,2) as output parameter. I am wondering, still the problem is in the essence of framework 5.0. Your help will be greatly appreciated.

Kumar

+6
source share
3 answers

I had the same issue with you and I solved it after linking to this article http://tiku.io/questions/1120572/decimal-output-parameter-rounded-to-integer-in-ef5-0

There are 3 steps to solving this problem:

  • Right-click the edmx file => Open with ... => XML (text) editor.
  • search text <Parameter Name="b" Type="numeric" Mode="InOut" /> then replace it with <Parameter Name="b" Type="numeric" Mode="InOut" Precision="20" Scale="2" />
  • find the text <Parameter Name="b" Mode="InOut" Type="Decimal" /> , then replace it with <Parameter Name="b" Mode="InOut" Type="Decimal" Precision="20" Scale="2" />

Hope this helps you!

+8
source

I have the same problem in EF6! But find a simple solution. I am trying to set the output value of an ObjectParameter, then return a decimal value with a scale like 5602.86

 public decimal GetQuotationAmount(string rec_id, decimal price) { ObjectParameter qTA_AMT = new ObjectParameter("QTA_AMT", typeof(decimal)); qTA_AMT.Value = 100000.00m; db.GRP_Calc_QuotationAmount(rec_id, price,qTA_AMT); return Convert.ToDecimal(qTA_AMT.Value); } 
+3
source

No, this is not fixed in EF 5.0. It will probably not be fixed in version 6.0 either.

UPDATE :
I recently updated EF 6.0, and no, the problem is still not fixed. I believe that EF 6.0 is now Open Source , so you can always fix it if you are busy with it.

+2
source

Source: https://habr.com/ru/post/951472/


All Articles