Entity framework database-first approach stored procedure with output parameter and result set
<p>I am using database-first approach for Entity Framework in my ASP.NET project. I have a stored procedure that has an output parameter <code>@TotalCount</code> and it returns a result set using a <code>SELECT</code> statement. </p>

<p>When I add the stored procedure in my <code>MyDbContext.edmx</code> file, the <code>MyDbContext.cs</code> has a function that returns an int (probably the output parameter) that is automatically generated for the stored procedure. </p>

<p>How can I access both the output parameter as well as the result set with this approach?</p>

<p>The stored procedure snippet is given below. Basically I am trying to do pagination in the stored procedure.</p>

<pre><code>CREATE PROCEDURE [dbo].[sp_GetDetailsForStudent]
    @StudentId BIGINT,
    //....
    @OrderBy NVARCHAR(max),
    @Page INT OUTPUT,
    @Items INT = 200,
    @TotalCount INT OUTPUT
    //.....

    SET @SortSql = N'SELECT * FROM #tmpTable'
    //......    
    EXEC sp_executesql @SortSql;
</code></pre>

<p>In the <code>MyDbContext.cs</code> file</p>

<pre><code> public virtual int sp_GetDetailsForStudent(parameters ...){
     //......
     return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("sp_GetDetailsForStudent", input parameters..., totalCount);
 }
</code></pre>