What is Entity Framework? Approaches of Entity Framework
What is Entity Framework?
“Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access code that developers usually need to write.”
Entity Framework is an open-source ORM framework for .NET applications supported by Microsoft. It enables developers to work with data using objects of domain specific classes without focusing on the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code compared with traditional applications.
Other ORMS like entity framework are -Hibernate, DataObjects.Net, NHibernate, OpenAccess, SubSonic
Entity Framework Architecture
Entity framework has following architecture –
EDM (Entity Data Model): EDM consist three main parts- Conceptual model, Mapping and Storage model.
Conceptual Model: Conceptual model is your model classes and their relationships. This will be independent from your database table design.
Storage Model: Storage model is your database design model which includes tables, views, stored procedures and their relationships and keys.
Mapping: Mapping consist information about how your conceptual model is mapped to storage model.
LINQ to Entities: LINQ to Entities is query language used to write queries against the object model. It returns entities which are defined in the conceptual model. You can use your LINQ skills here.
What are the approaches in Entity Framework?
Entity framework support following approaches –
Database First (4.0): – used if your database is already exits, generate model from existing database. After this we use that model to write a code or develop the application.
Model First (4.1) :- used if your database not exits, we create entity model by drawing the entity class diagram using entity drawing tool. Once class diagram is ready we can generate database.
Code Frist (5.0) :- used if your database not exits, we create entity data model by writing classes or C# code, after this we use the the model , it will generate database automatically. Code first is Most popular approach.