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();
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();
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.
In this article, We learn how to create or generate Migration Script. I will show how to do it, and just follow the steps clearly. […]
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 […]
In this article we learn how to address if you encounter this issue in your development journey. I will show you how, Just follow the […]
In this article, I will show how to create .NET Core API using Entity Framework Code First Approach. I will develop Student Web API application […]