I have a stored procedure call but i want to get the return value of the stored procedure. Return type is integer. Following the code where I am calling the stored procedure
else if(ReportName=="LandMarkInOutReport")
{
_DBContext.LandMarkInOutReport(report.ReportParameters.StartDate, report.ReportParameters.EndDate, Convert.ToInt64(paramArr1[3]), Convert.ToInt32(paramArr1[9]), Convert.ToInt32(paramArr1[11]), paramArr1[5], paramArr1[7]);
}
So please guide me how can I get the return value and also that is it the correct way to call stored procedure in entity framework?
Database First
First, you have to add your stored procedure to the .edmx file. If you have a context variable _DBContext and the stored procedure is called LandMarkInOutReport , you can execute it like this:
LandMarkInOutReport_Result returnValue = _DBContext.LandMarkInOutReport(report.ReportParameters.StartDate, report.ReportParameters.EndDate, Convert.ToInt64(paramArr1[3]), Convert.ToInt32(paramArr1[9]), Convert.ToInt32(paramArr1[11]), paramArr1[5], paramArr1[7]).FirstOrDefault();
The stored procedure call without .FirstOrDefault()
isn't executed on the database.
Now you can use the returnValue to call the correct variable eg.: returnValue.ReturnVariableName .
Code First
You can call the stored procedure with .SqlQuery<> :
int returnValue = _DBContext.SqlQuery<int>("LandMarkInOutReport @StartDate, @EndDate, @param3, @param4, @param5, @param6, @param7",
new SqlParameter("StartDate", report.ReportParameters.StartDate),
new SqlParameter("EndDate", report.ReportParameters.EndDate),
new SqlParameter("param3", Convert.ToInt64(paramArr1[3])),
new SqlParameter("param4", Convert.ToInt32(paramArr1[9])),
new SqlParameter("param5", Convert.ToInt32(paramArr1[11])),
new SqlParameter("param6", paramArr1[5]),
new SqlParameter("param7", paramArr1[7])).FirstOrDefault();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.