connect with your database using Entity-Framework database first approach

Today I will show you how to connect with your SQL server with Entity-framework using Database first approach.

First create a new MVC project in Visual studio.

Now right Click on your web-project and navigate to Add->New item A Dialoug box will appear select options as given in below image.

You can change the name of Datamodel which is Model1.edmx in my case. Now click Add

Select Generate from Database. and click Next.

Next set-up is making connection string with your existing database

So click on Create new connection. Connection properties dialogue box will appear.Select server name and desired database. Provide user name and password if required.

Entity-framework Tutorial

Click on test connection. if connection succeed then click ok

Click Next and new screen will appear on which you decide which tables you want to include in this data model

In my case my database is NorthWind database and only two table customers and employees

Entity-framework Tutorial

Click Finish.

Visual studio automatically Generate Database context classes code and required dlls

Entity-framework Tutorial

you can see your database schema in visual studio.when ever you make change in your database schema you need to update your Datamodel.