Entity Framework Model First approach, enable to you create your model in Entity Framework designer and then generate SQL file, which will create database schema to match your model .After generating  you execute the SQL file to create the schema in your database. The classes that you communicate with in your application are automatically generated from the EDMX file.

So, Entity Framework Model First approach, add new ADO.NET Entity Data Model and Select Empty EF Designer model in Entity Data Model Wizard. Following is a simple example of creating a new MVC 4 project using Model First approach.

 Select ADO.NET Entity Data Model from wizard and enter name Article in the Name field.

Now Click on Empty Entity Data Model Wizard dialog.

Right-click on the designer and select Add New  Entity

Add Entity Name as shown in the following image.

Show below your entity created:

Now Right-click on the add new entity on the design table and select Add New  Scalar Property, enter Name as the name of the property.

Enter your property name show below:

After creating property name your entity looks like below:

After creating the required entities, right click on designer > click to Generate database from model.

Following open Generate Database Wizard. You can select existing database or create a new connection by clicking on New Connection. 

Select database server and enter the name of the database with credential to create and then click OK.

After clicking ok it will ask you for the confirmation for creating a new database. Click yes to create a database.

If you want to save connection string check save entity checkbox and click on next button.

Now Select your targeted entity framework and click on next button.

Click finish to generate DDL for the DB model as shown below.

Now go to solution explorer and Right click on article.edmx.sql to execute script

Now Server connection dialog will open where enter your database login details.

After executed see your table has been created as show below.

Now Use blogs table to insert a record with entity framework.

         ArticleContainer db = new ArticleContainer();
            Blog blog = new Blog();
            blog.Title = "what is mvc";
            blog.Description = "test";

Now select your table see record inserted.

 select * from Blogs




Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like