1

Using Simple.Data, I would like to get the result from an output parameter in a stored procedure. Let's say I have the following SP (disregard the uselessness of it):

CREATE PROCEDURE [dbo].[TestProc]
    @InParam int,
    @OutParam int OUTPUT
AS
BEGIN
    SELECT @OutParam = @InParam * 10
END

When I call it with Simple.Data, I use the following code.

var db = Database.Open();

int outParam;
var result = db.TestProc(42, out outParam);

Console.WriteLine(outParam); // <-- == 0
Console.WriteLine(result.OutputValues["OutParam"]); // <-- == 420

It feels like outParam should contain the value, and not the OutputValues dictionary. So my question is: Is there a nicer way to get the result from OutParam in this particular case?

Captain JiNX
  • 93
  • 1
  • 5

1 Answers1

3

Unfortunately, out parameters are not supported by the dynamic binding infrastructure used by Simple.Data, as they are not supported in all CLR languages.

I am open to suggestions for better syntax, though.

Mark Rendle
  • 9,274
  • 1
  • 32
  • 58
  • if you could call it without the need of sending outParam as an argument it would look nice. Just db.TestProc(42); (I have no idea if it's even possible...) – Captain JiNX Sep 20 '12 at 14:38
  • 1
    If you change the stored procedure and supply a default value for the output parameter, you don't need to pass it. `CREATE PROCEDURE TestProc(@Answer INT, @Question INT = NULL OUTPUT)` then `db.TestProc(42);` will work fine. – Mark Rendle Sep 21 '12 at 12:56