I'm using Entity Framework with a code-first approach. Can you provide some suggestions on how to call a stored procedure from my code?
Stored procedure:
create procedure sp_GetCountry
As
Begin
select *
from Country
End
Homectrol.cs
:
JanContext db = new JanContext ()
public JsonResult GetCountry_sp()
{
string storedprocedure = "sp_GetCountry";
}
public JsonResult GetCountry_sp()
{
// string storedProcedure = "sp_GetCountry";
var Country = db.Countries.SqlQuery("sp_GetCountry").ToList();
return new JsonResult { Data = Country, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
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.