In this article, We can learn how to consume Stored Procedure (SP) using Entity Framework in .Net Core. I will show you how to do it, just follow the steps clearly.

For more updates please do Subscribe via Email:

Consuming Stored Procedure using Entity Framework in .Net Core

I am currently a software development analyst and part of the team who develop Microsoft project. We are using Microsoft technology such as .Net framework, Azure services and others.

Entity Framework is one of the best approach by doing programming in the latest standard coding. No matters if it is a code first approach or not. By using new technology and advance approach of doing programming by implementing entity framework in your project.

One of the business requirement implementation by using entity framework approach is not pass by the quality Assurance and testing team cause of different reason. The team restructure by implementing store procedure than to EF approach. But the client didn’t want to implement by using SQL Command. They wanted to implement is in entity framework calling stored procedure.


This is how we implement it.

Declare variable sqlContext as Database Context.

var sqlContext = new DBContext();

Code Implementation.

 var param1 = new SqlParameter();
            param1.ParameterName = "@param1";
            param1.SqlDbType = SqlDbType.Int; // parameter #1 datatype.
            param1.SqlValue = 0; // parameter #1 value.

var param2 = new SqlParameter();
            param2.ParameterName = "@param2";
            param2.SqlDbType = SqlDbType.NVarChar; // parameter #1 datatype.
            param2.SqlValue = "param2"; // parameter #1 value.

            // DBTable assuming the table name.
            // SP_Sample assuming the Stored proc name.
var response = this.sqlContext.DBTable.SqlQuery("SP_Sample @param1, @param2", param1 ,param2 ).AsEnumerable();

Happy Learning..

Thank you for visiting my blog site. Hoping you learn more here. please feel free to comment and suggest if there is need to enhance and update. thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *