QUESTION
How do I access the 'Results', 'Messages', and 'Return Value' of a Stored Procedure using Entity Framework 4.4 and C# 4.0?
Below is the Stored Procedure that takes three parameters. One way or another when I run the Store Procedure I should, I hope, be able to access all three values for 'Results', 'Messages', and 'Return Value'.
Can someone help me figure out how to do that with EF? Using the code that is generated out of EF all I seem to be able to access is the 'Results' of the query ( returned rows )
Stored Procedure
USE [THIS_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[THIS_PROCEDURE]
@FIRST_PARAM CHAR(17) = NULL,
@SECOND_PARAM CHAR(2) = NULL,
@THIRD_PARAM CHAR(5) = NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ReturnValue INT = 0;
IF COALESCE(@SECOND_PARAM, 'XX') NOT IN ('XX', 'YY')
BEGIN
RAISERROR('Invalid @SECOND_PARAM value: %s; @SECOND_PARAM mXXt be XX or YY.', 2, 1, @SECOND_PARAM ) WITH SETERROR;
SET @ReturnValue = -50100;
END
IF COALESCE(@SECOND_PARAM, 'XX') = 'YY'
BEGIN
RAISERROR('@SECOND_PARAM value: %s; YY is valid, but currently is not supported, returning XX results.', 2, 1, @SECOND_PARAM) WITH SETERROR;
SET @ReturnValue = -50105;
END
IF COALESCE(@THIRD_PARAM, 'XX-EN') NOT IN ('XX-EN')
BEGIN
RAISERROR('Invalid @THIRD_PARAM value: %s; @THIRD_PARAM mXXt be XX-EN.', 2, 1, @THIRD_PARAM) WITH SETERROR;
SET @ReturnValue = -50101;
END
SELECT DISTINCT
THESE.VALUES
FROM dbo.THIS_TABLE
WHERE THESE.CONDITIONS;
IF @@ROWCOUNT = 0
BEGIN
DECLARE @SP_MATCHCOUNT INT
EXEC @SP_MATCHCOUNT = [dbo].[MATCHTABLE] @PATTERNH = @PATTERN
IF @SP_MATCHCOUNT > 0
BEGIN
RAISERROR('Mapping from HERE to HERE not found for PATTERN: %s.', 2, 1, @PATTERN) WITH SETERROR
SET @ReturnValue = -50103;
END
ELSE
BEGIN
RAISERROR('PATTERN Pattern not found for PATTERN: %s.', 2, 1, @PATTERN) WITH SETERROR
SET @ReturnValue = -50104;
END
END
RETURN @ReturnValue
END
CODE
public virtual ObjectResult<THIS_PROCEDURE_RESULT> THIS_PROCEDURE_METHOD(string FIRST, string SECOND, string THIRD)
{
var FIRST_PARAM = FIRST != null ?
new ObjectParameter("FIRST", FIRST) :
new ObjectParameter("FIRST", typeof(string));
var SECOND_PARAM = SECOND != null ?
new ObjectParameter("SECOND", SECOND) :
new ObjectParameter("SECOND", typeof(string));
var THIRD_PARAM = THIRD != null ?
new ObjectParameter("THIRD", THIRD) :
new ObjectParameter("THIRD", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<THIS_PROCEDURE_RESULT>("THIS_PROCEDURE", FIRST_PARAM, SECOND_PARAM, THIRD_PARAM);
}