Recently, I had to return only one value in addition to the tabular data returned by my stored procedure. Since EF does not support stored procedures with multiple result sets, I decided that I could accomplish this with an output parameter. However, using this method, I ran into a problem when I only returned rounded values ββfor some numeric value fields.
The parameter of my stored procedure was declared as:
@MyValue numeric(19,6) output
When calling the mapping function, I had:
var myValue = new ObjectParameter("MyValue", typeof(decimal)); List<MyResultItem> results = this.ObjectContext.CallMyStoredProc(someId, myValue).ToList();
This is what always returned a value rounded to the nearest integer (i.e. scaling zero).
At first, I was able to fix this by manually editing the basic XML in .edmx, manually adding the Precision and Scale attributes:
<Parameter Name="MyValue" Type="numeric" Mode="InOut" Precision="19" Scale="6" />
It was not surprising that it was completely discarded the next time I executed the command βUpdate Model from Databaseβ.
I seem to have fixed this more reliably by updating my declaration for ObjectParameter as such:
var myValue = new ObjectParameter("MyValue", 999999999.999999M);
However, it seems awful how to hack, and I'm worried about problems in the future (even if it's just a service regarding this magic number). Is there a better and more reliable way to use the output parameters in the Entity Framework?