Creating Stored Procedures With Entity Framerwork

This article explains how to create Stored Procedures with Entity Framerwork. I do not want to use the ToList() method, I just want to use my own methods. Let's start.

Step 1: First of all open SQL Server 2008 R2 (for me) and I will use the Northwind database that you are familiar with.

Provide your procedure name and then write your query. Execute your query (F5), the result is that the command(s) were completed successfully.

Is it perfect? (Ha:)) Now refresh the Programmability folder then click "Toggle"; here is the Stored Procedure.


Step 2: Now open your Visual Studio 2012 and select "File" >> "New" >> "Project..." >> "Windows Forms Application" (the project name is "UsingStoreProc"). Click the "OK" button.
Note : If you have no idea of how create a new Entity Framework structure you should visit this page:

Drag the DataGridView and set the dock in parent container.

Step 3: Create  a new Entity Framework connection.


Choose your Entity Model. Generate from database or Empty Model. I should use the first one.


Click the "Next" button.
The next screen will display the connection settings.



Server Name: The default server name is "sa". We can say system admin.

Log on to the server: This is your security properties. How to log on your database server?

Connect to the database: Select your database from here.

Test Connection: If you have a problem about the connection then this button will say that something is wrong.
And then click the "Ok" button.
That provides all the settings for your connection string, including the database name, security settings and so on.

Click the "Next" button.

Now this page is really great. Click the Stored Procedures and Functions.

Now  choose the Stored Procedure name. Oh there is the CategoryList method. Go on.

Open your Windows Forms application and click the form_load.


CategoryList() is a method. Execute the project; the result is:


Up Next
    Ebook Download
    View all
    View all