c# - Entity framework database-first approach stored procedure with output parameter and result set -


i using database-first approach entity framework in asp.net project. have stored procedure has output parameter @totalcount , returns result set using select statement.

when add stored procedure in mydbcontext.edmx file, mydbcontext.cs has function returns int (probably output parameter) automatically generated stored procedure.

how can access both output parameter result set approach?

the stored procedure snippet given below. trying pagination in 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 * #tmptable'     //......         exec sp_executesql @sortsql; 

in mydbcontext.cs file

 public virtual int sp_getdetailsforstudent(parameters ...){      //......      return ((iobjectcontextadapter)this).objectcontext.executefunction("sp_getdetailsforstudent", input parameters..., totalcount);  } 

first need update edmx model function

public virtual int sp_getdetailsforstudent(parameters ...){....}

should like

public virtual objectresult<yourresult_type> sp_getdetailsforstudent(parameters ...){....}

for refreshing edmx model go hear

you might need choose "create new complex type" option instead of "update" suggested in above link.

then fetch result can use below code

objectparameter outparam1 = new objectparameter("outparameter", typeof(long)); var db = new yourdbcontext(); var res = db.sp_getdetailsforstudent(parameter1,parameter2,outparam1 ); foreach (yourresult_type item in res ) { var prop1= item.property1; } var outparam1value= outparam1.value;


Comments