Sunday, 27 September 2015
Friday, 25 September 2015
USING STORED PROCEDURE IN ENTITY FRAMEWORK WITH INPUT PARAMETER
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.
Wednesday, 9 September 2015
USING STORED PROCEDURE IN ENTITY FRAMEWORK WITHOUT INPUT OUTPUT PARAMETER
Lesson - 5
Using Stored Procedure in Entity Framework Without Input and Output Parameters
Let's create a stored procedure. Let have example select all employee.
Now lets add it into the Entity Data Model EDMX.
Now click on the Model Browser and from Stored Procedure / Function.(Function Import)
double click on the stored procedure.
Now you will see Function Import window. then click on the Get Column Information
All selected columns will be appeared. then click ok.
Get the result and return it to the view from the controller
populate the result in the view.
thank you
Subscribe to:
Posts (Atom)