I am new to .NET Core and used to working with ASP.NET MVC. I am working on a project using .NET Core 2.2 and Entity Framework Core. I am not sure how to add my stored procedure into this project as before I was used to do it through .edmx
file.
public ActionResult GetData()
{
using (DBContext db = new DBContext())
{
//db.Configuration.LazyLoadingEnabled = false;
var result= db.usp_GetOpenSorts();
return Json(new { data = results.ToList() });
}
}
This is how I am used to calling my stored procedure before but now I am not sure how to do it.
Thanks
You can add a stored procedure by generating an empty migration and adding the following code to it:
public partial class MyMigration: Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"CREATE PROCEDURE [dbo].[MyProcedure]
AS
BEGIN
-- code here
END
");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DROP PROCEDURE [dbo].[MyProcedure]");
}
}
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.