In this article, we will show you how to use Entity Framework Database First In Desktop or Windows Forms Application.
Step 1: For this purpose, we will use the database as shown in the figure. This database has only one Table called "Students". You can use any database, you like.
Step 2: Create A New Windows Forms Application In Visual Studio Or Use An Existing Application.
Step 3: Now, add An “ADO.NET Entity Data Model” to your Project. For that, right-click on your project, then "Add" and select "New Item...". This will open "Add New Item" Window. Select "ADO.NET Entity Data Model", give it some name and click on "Add" Button. The steps are shown below.
Step 4: Select “EF Designer from database” option and Click “Next >” Button.
Step 5: Click on “New Connection” to add new connection ....
When you click on "New Connection...." will open the screen below. Just provide "Server name" and "Select or enter a database" and click "OK" Button. This will close "Connection Properties" Window then click "Next >" button.
Step 6: Select “Entity Framework 6.x” option and Click “Next >” Button.
Step 7: Select “Tables, Views, Stored Procedures and Functions”. Since the database we are using has only 1 table and no views, stored procedures and function. So I will select "Students" Table only and Click “Finish” Button.
If you see the following "Security Warning", just check "Do not show this message again" and click "OK" Button.
Once the process is complete, Entity Framework will add “References” in your project and “Connection String” in App.Config file.
It will also generate "Context Class" for us as shown below.
It will also generate "Entity Class(es)" for us as shown below.
Happy Coding!!!
No comments:
Post a Comment