I am using database-first approach for Entity Framework in my ASP.NET project. I have a stored procedure that has an output parameter @TotalCount
and it returns a result set using a SELECT
statement.
When I add the stored procedure in my MyDbContext.edmx
file, the MyDbContext.cs
has a function that returns an int (probably the output parameter) that is automatically generated for the stored procedure.
How can I access both the output parameter as well as the result set with this approach?
The stored procedure snippet is given below. Basically I am trying to do pagination in the stored procedure.
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;
In the MyDbContext.cs
file
public virtual int sp_GetDetailsForStudent(parameters ...){
//......
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("sp_GetDetailsForStudent", input parameters..., totalCount);
}