Menu Close

Entity Framework Architecture


In this article we will learn about Entity Framework Architecture. The Entity Framework is a set of technologies in ADO.NET that support the development of data-oriented software applications. Please read the articles of .NET.

What is Entity Framework?

Entity Framework (EF) is an open source object–relational mapping (ORM) framework for ADO.NET. It was originally shipped as an integral part of .NET Framework. Starting with Entity Framework version 6, it has been delivered separately from the .NET Framework.

The Entity Framework is a set of technologies in ADO.NET that support the development of data-oriented software applications. Architects and developers of data-oriented applications have struggled with the need to achieve two very different objectives. They must model the entities, relationships, and logic of the business problems they are solving, and they must also work with the data engines used to store and retrieve the data. The data may span multiple storage systems, each with its own protocols; even applications that work with a single storage system must balance the requirements of the storage system against the requirements of writing efficient and maintainable application code.

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with 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 than in traditional applications. Because the Entity Framework is a component of the .NET Framework, Entity Framework applications can run on any computer on which the .NET Framework starting with version 3.5 SP1 is installed.

The following figure shows the overall architecture of the Entity Framework.

entity-framework

EDM (Entity Data Model): EDM consists of three main parts – Conceptual model, Mapping and Storage model.

Conceptual Model: The conceptual model contains the model classes and their relationships. This will be independent from your database table design.

Storage Model: The storage model is the database design model which includes tables, views, stored procedures, and their relationships and keys.

Mapping: Mapping consists of information about how the conceptual model is mapped to the storage model.

LINQ to Entities: LINQ-to-Entities (L2E) is a 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.

Entity SQL: Entity SQL is another query language (For EF 6 only) just like LINQ to Entities. However, it is a little more difficult than L2E and the developer will have to learn it separately.

Object Service: Object service is a main entry point for accessing data from the database and returning it back. Object service is responsible for materialization, which is the process of converting data returned from an entity client data provider (next layer) to an entity object structure.

Entity Client Data Provider: The main responsibility of this layer is to convert LINQ-to-Entities 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 the database.

ADO.Net Data Provider: This layer communicates with the database using standard ADO.Net.

Schema definition language

ADO.NET Entity Framework uses an XML based Data Definition Language called Schema Definition Language (SDL) to define the EDM Schema. The SDL defines the Simple Types similar to the CTS primitive types, including String, Int32, Double, Decimal, Guid, and Date Time, among others. An Enumeration, which defines a map of primitive values and names, is also considered a simple type. Enumerations are supported from framework version 5.0 onwards only. Complex Types are created from an aggregation of other types. A collection of properties of these types define an Entity Type.

EntityType ::= 
    ENTITYTYPE entityTypeName [BASE entityTypeName]
      [ABSTRACT true|false] KEY propertyName [, propertyName]*
      {(propertyName PropertyType [PropertyFacet]*) +}

  PropertyType ::= (
        (PrimitiveType [PrimitiveTypeFacets]*)
        | (complexTypeName)
        | RowType
    
      PropertyFacet ::= (
        [NULLABLE true | false]
        | [DEFAULT defaultVal] 
        | [MULTIPLICITY [1|*]]
      )
    
      PropertyTypeFacet ::= 
        MAXLENGTH | PRECISION | SCALE 
        | UNICODE | FIXEDLENGTH | COLLATION
        | DATETIMEKIND | PRESERVESECONDS
    
      PrimitiveType ::= 
        BINARY | STRING | BOOLEAN
        | SINGLE | DOUBLE | DECIMAL | GUID
        | BYTE | SBYTE | INT16 | INT32 | INT64
        | DATETIME | DATETIMEOFFSET | TIME
  )

Conclusion

So far in this article we learnt Entity Framework Architecture.


Leave a Reply

Your email address will not be published.