28
AugVarious Domain modelling approaches in Entity Framework
A business domain is populated with related and interconnected entities which have its own properties and behavior. Most important thing is that each entity may have a state and can be bound to a possibly dynamic list of validation rules. EF allow developers to focus on the business domain and to model it in terms of classes.
Domain modelling approaches
There are three approaches of domain modelling which was introduced with Entity Framework 4.1
Code First
Code first is the domain modelling approach in Entity Framework. It enables you to describe a model by using C# or VB.NET classes and then create database from these classes. These classes are called POCO classes.
This approach enables us to work entirely in an object-oriented direction, and not worry about the structure of the database. This abstraction allow us to make a more logically and flexible application that focuses on the behaviour of the application rather than the database generated by it.
Advantages of Code First
Model First
Model first is the domain modelling approach in Entity Framework. It enables you to create model’s Entities, relationships, and inheritance hierarchies on the design surface of empty model (.edmx file) by using entity designer and then create database from it. This approach is adopted by the architect and solution lead developers.
In Model First approach, while creating Entity Data Model, you must select the option “Empty Model” instead of "Generate from database" option.
Advantage of Model First
Database First
Database first is the domain modelling approach in Entity Framework. It enables you to create model from an existing database (like SQL Server, Oracle, DB2 etc.). This approach reduces the amount of code that we need to write since it automatically generates code. But it also limits us to work with the structure of the generated code.
Advantage of Database First
What do you think?
I hope you will enjoy the domain modeling approaches while programming with EF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.
Take our Entityframework skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.