USING STORED PROCEDURE IN ENTITY FRAMEWORK WITH INPUT PARAMETER
In this lesson we will see how to use stored procedure with input parameter in entity framework
First let us create a new empty project in MVC.
I have employee table with few records. let us display the records using Entity Framework and Stored Procedure.
I have created a stored procedure to get Employee by Id. Below is the stored procedure.
create procedure getEmployee
@id int
as
begin
select * from employee where id = @id
end
Now time to Add New Entity Model to the project.
Once we add Entity Data Model, the Build the project.
Now click on the Entity Data Model. Select Model Browser tab. Then double click on the stored procedure.
Then we find the procedure at function import folder, again double click on the stored procedure under function import.
Now you see popup window like below. click the on the get column information and you will get all the column information of the stored procedure.
Finally you can click ok. Now you will find the stored procedure under Complex Type Folder, that is the entity object we going to consume in our project.
Now let us go to HomeController. First we need to include the namespace of the dbcontext.
Now let us go to HomeController. First we need to include the namespace of the dbcontext.
No comments:
Post a Comment