Creating a .edmx File using Entity Data Model

This article explains how to create an edmx file, write the Lambda Expression and the last one is CRUD (Insert, Update, Delete and Select).

First of all create a database (I am using the Northwind database.).

Step 1:

Create a new Windows Form Application project:

Create-Edmx-File-1.jpg

Step 2:

"EntityFrameWorkSample" >> "Add" >> "New Item" >> "Data" >> "ADO.NET Entity Data Model"

On the other hand write your model name (Model1.edmx is the default name; I do not want to change it) and push the "Add" button.

Create-Edmx-File-2.jpg

Step 3:

Choose the model content. I used "Generate from database".

Create-Edmx-File-3.jpg

Step 4:

There is the Entity Connection. If you want to change this connection string open the App.config file.

Create-Edmx-File-4.jpg

If you have no connection then you must create a new connection from the "New Connection" button and choose your database.

Choose Your Server Name and "Log on to the server" (this is the security level) and finally select your database. I used the Northwind database. Click the "Ok" button.

Create-Edmx-File-5.jpg

Step 5:

Choose the Categories table and select this one. Click the "Finish" button.

Create-Edmx-File-6.jpg

Step 6:

The model will be generated and opened in the EDM Designer.

Create-Edmx-File-7.jpg

How to display data on the DataGridView?

Create-Edmx-File-8.jpg

Create-Edmx-File-9.jpg

How to insert data from the Categories table?

Create-Edmx-File-10.jpg

I changed the button name from Designer (btnInsert) and changed the Textbox name (tbCategoryName, DescriptionName). If I insert new data, I should use the Add method.

How to use SelectionChangeCommitted Event?

Create-Edmx-File-11.jpg

How to delete your data from the Categories table?

Create-Edmx-File-12.jpg

How to update your data from the Categories table?

Create-Edmx-File-13.jpg