The first database approach is missing in EF Core with edmx files. Instead, you need to use Scaffold-DbContext
Install Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.SqlServer.Design Nuget Packages
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
but this will not get your stored procedures. It's still at work tracking issue # 245
But to execute stored procedures, use the FromSql method , which executes RAW SQL queries
eg,
var products= context.Products
.FromSql("EXECUTE dbo.GetProducts")
.ToList();
For use with options
var productCategory= "Electronics";
var product = context.Products
.FromSql("EXECUTE dbo.GetProductByCategory {0}", productCategory)
.ToList();
or
var productCategory= new SqlParameter("productCategory", "Electronics");
var product = context.Product
.FromSql("EXECUTE dbo.GetProductByName @productCategory", productCategory)
.ToList();
There are certain restrictions on the execution of RAW SQL queries or stored procedures. You cannot use it for INSERT / UPDATE / DELETE. if you want to execute INSERT, UPDATE, DELETE queries, use the ExecuteSqlCommand command
var categoryName = "Electronics";
dataContext.Database
.ExecuteSqlCommand("dbo.InsertCategory @p0", categoryName);