Entity Framework is an object-relational mapping (ORM) framework that allows mapping of a Microsoft SQL Server and non-Microsoft database tables to .NET classes, and query of the resulting objects using LINQ To Entities.
|EDM (Entity Data Model)||Consists into three main parts- Conceptual model, Mapping and Storage model|
|Conceptual Model||Contains the model classes and their relationships. This will be independent from the database table design|
|Storage Model||Database design model which includes tables, views, stored procedures and their relationships and keys|
|Mapping||Information about how the conceptual model is mapped to storage model|
|LINQ to Entities||Query language (L2E)used to write queries against the object model. It returns entities, which are defined in the conceptual model|
|Entity SQL||Alternative query language. However, it is a little more difficult than L2E and also the developer will need to learn it separately|
|Object Service||Main entry point for accessing data from the database and to return it back. This component responsible for the process materialization, which is the process of converting data returned from entity client data provider to an entity object structure|
|Entity Client Data Provider||The main responsibility of this layer is to convert L2E or Entity SQL queries into a SQL query which is understood by the underlying database. It communicates with the ADO.NET data provider which in turn sends or retrieves data from database|
|ADO.Net Data Provider||This layer communicates with database using standard ADO.NET.|
DbContext is the newer API which should be used when using most common tasks since the API is better designed and is simpler to use. For complex tasks it is still necessary to get ObjectContext from DbContext and use the older API.
Entity framework (EF) is useful in three scenarios. The best approach can be achieved following the decision tree ilustrated next:
Code First: This scenario includes (1) targeting a database that doesn’t exist , (2) an empty database that Code First will create and/or add new tables too, or (3) an existing database.
Code First allows to define the model using C# or VB.Net POCO classes. O/R mapping can optionally be performed using DataAnnotation (attributes) on the classes and properties or by using a fluent API.
No Visual Designer is used. When using the Code First approach, the DbSet<TEntity> properties on the derived DbContext class are used to build a model following specific conventions (rules).
Database First-approach: The developer wants to use a Visual Designer and the database is designed first than the other parts of the application.
Entity Framework allows to reverse engineer a model from an existing database. The model is stored in an EDMX file (.edmx extension) and can be viewed and edited in the Entity Framework Designer. The classes that the application interact with are automatically generated from the EDMX file:
Refer to this article for details.
Entity Framework allows to create a new model using the Entity Framework Designer and then generate a database schema from the model. The model is stored in an EDMX file (.edmx extension) and can be viewed and edited in the Entity Framework Designer. The classes that the application interact with are automatically generated from the EDMX file:
Refer to this article for details.
Entity Framework 5.0 (EF) and prior versions was distributed at two places:
- The .NET Framework - core components on System.Data.Entity.dll assembly; and
- The EntityFramework NuGet Package which includes the EntityFramework.dll assembly.
Entity Framework is now an open source framework by Microsoft that can be obtaned codeplex.