A Simple Step to Entity Framework: Model First Approach

Introduction

In the previous articles we learned about the Code First Approach and Database First Approach of Entity Framework.

The Model First Approach provides the option to create entities and relationships directly on the design interface of the EDMX and then we can execute it.

A quick start

Create an application.

Create an application

Add new item.

Add new item

Add ADO.NET Entity Data Model.

Entity Data Model

Select Empty Model.

Select Empty Model

Right-click on the designer then select Add New => Entity.

Add New Entity

Enter the entity name in this Wzard.

Enter the entity name

Right-click and add the new scalar property.

add new scalar property

Then click on the option Generate Database from Model.

Generate Database from Model

Enter the Sever details and DB Name.

server name

Sever details

Our connection details are here.

connection details

In the Summary and Settings, click on Finish.

Summary of settings

Now our MyModel.edmx.sql file has been created.

MyModel edmx

Right-click on the file then select Execute.

execute file

Add a Code Generation item.

add code generation

Code Generation item

All the files are created in the solution.

created in the solution

Check with the DB server, the database and tables are created.

Check with DB server

If we need to update/add new items in/to the model, add the item in the model and generate the db then our .sql file will update and execute the file again.

execute the file again

Conclusion

In this article we learned the basic details of the Model First Approach of the Entity Framework.

Up Next
    Ebook Download
    View all
    Learn
    View all