Every
business application has a conceptual data model (explicit or
implicit) which describes the various elements of the problem domain
as well as each element's structure, the relationships between each
element and their constraints.We follow different approaches to deal
with these models. Entity Framework also provides three different
approaches to deal with the model.
Code First Approach:
This is a approach where we create the classes first and then create database directly from these classes. These classes are called POCO (Plain old CLR objects) classes. In code first, we never use the Entity Designer (for editing .edmx files) rather what we use is the POCO classes. This approach allow us to make a more logically and flexible application that focuses on the behavior of the application rather than the database generated by it. We can also use Code first to map our model to an existing database. This approach first comes with Entity frame work 4.1 (Visual Studio 2010 ).
- Database First
- Model First
- Code First
Let's
discuss these approaches one by one.
Database
first approach:
This is a approach where we created the model codes (classes, properties, DbContext etc.) from an existing database. We achieve this by using Visual Studio’s Entity Data Model Wizard . This approach first comes with Entity frame work 3.5 (Visual Studio 2008 ).
This is a approach where we created the model codes (classes, properties, DbContext etc.) from an existing database. We achieve this by using Visual Studio’s Entity Data Model Wizard . This approach first comes with Entity frame work 3.5 (Visual Studio 2008 ).
Model
First Approach:
This is a approach where we create Entities, relationships and inheritance hierarchies directly on the design surface of empty model by using entity designer (.edmx file) and then generate database from it. This approach first comes with Entity frame work 4.0. (Visual Studio 2010 ).
This is a approach where we create Entities, relationships and inheritance hierarchies directly on the design surface of empty model by using entity designer (.edmx file) and then generate database from it. This approach first comes with Entity frame work 4.0. (Visual Studio 2010 ).
Code First Approach:
This is a approach where we create the classes first and then create database directly from these classes. These classes are called POCO (Plain old CLR objects) classes. In code first, we never use the Entity Designer (for editing .edmx files) rather what we use is the POCO classes. This approach allow us to make a more logically and flexible application that focuses on the behavior of the application rather than the database generated by it. We can also use Code first to map our model to an existing database. This approach first comes with Entity frame work 4.1 (Visual Studio 2010 ).
If you want to know when to use which approach and what is the advantage and disadvantages of the above approaches then you will find it here.
Hope this is helpful. :)
No comments:
Post a Comment