What is Entity Framework?
Definition (Microsoft): The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write.
Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects. The Entity Framework’s ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals.
From this definition we can understand that entity framework is an object relational mapper (ORM) framework, for automating database related activities for your application. It automates developer’s task for writing code for data access / data layer. It automates mechanism for accessing & storing the data in the data base.
To use Entity Framework in your applications any one of the following approaches can be used
- Code First – In this approach, you first create you POCO classes (entities) and their relationships and EF will used this classes to create your database based on the Classed ( Code First Example)
- Database First – In this approach, developers will use Entity Framework designer (EF designer from database template) and create an entity Data model ( EDM) by selecting an existing database to create entity classes and context, the file that is created using the designer has extension .edmx. Any changes to the database tables or relationship the .edmx file needs to be refreshed and it will refresh / regenerate you classes (entities), their relationships and context.
- Model First – In this approach, developer will use Entity Framework designer template (Empty EF designer model template) and create Entity Data Model (EDM) by not selecting any database, but creating classes ( entities), their relationships and inheritance hierarchies on the designer surface then used the .edmx file to create a database from this model.
Note: Entity Framework is an open source ORM framework from Microsoft, Other ORMs frameworks like DataObjects.Net, NHibernate, OpenAccess, SubSonic etc can be used for .net applications.
Entity Framework Architecture: