Friday, May 9, 2008

ADO.NET Entity Framework - Introduction

I have been using LINQ to SQL as an OR-mapper for my application since the release of Visual studio 2008. As a light weight OR-mapper and for RAD scenarios LINQ to SQL serves my purpose as a framework for persisting data. But when thinking about Enterprise Application development and real scenarios, I don’t find LINQ to SQL as powerful tool with all the features I require for Application development.

LINQ to SQL as present was not a competitor for NHibernate or LLBLGen which are the common OR-mappers available. If you are looking for a better OR-mapper from Microsoft, ADO.NET Entity framework is the answer. This one gives life to the conceptual modeling and has a lot of features compared to LINQ to SQL. The primary benefit of the ADO.NET Entity Framework is to elevate the level of abstraction at which developers can work when they deal with data and to decrease the amount of code that is required to create and maintain data-oriented applications.

Some of the advantages of using Entity framework:

  • Entity framework maps relational tables, columns, and foreign key constraints to entities and relationships in conceptual models. Instances of these classes are populated with data and data changes are saved based on defined mappings between the conceptual and storage model.
  • Supports Entity SQL and LINQ to Entities two powerful query languages to query the data.
  • Provides a rich and intuitive view to the data model from the application perspective as opposed to the normalized view of data.
  • Last but not least, comes with a code generation wizard that is integrated with Visual Studio that will create less and more quality code much faster.

In this article series I will be explaining the underlining technologies in the Entity Framework by some tutorials that help you to get hands on experience on the topic.

The architecture

The ADO.NET Entity Framework is a layered framework which abstracts the relational schema of a database and presents a conceptual model.

  • Object Services: Object Services is a component of the Entity Framework that enables you to query, insert, update, and delete data, expressed as strongly-typed CLR objects that are instances of entity types. Object Services supports both Language-Integrated Query (LINQ) and Entity SQL queries against types defined in an Entity Data Model (EDM). Object Services materializes returned data as objects, and propagates object changes back to the persisted data store. It also provides facilities for tracking changes, binding objects to controls, and handling concurrency. Object Services is implemented by classes in the System.Data.Objects and System.Data.Objects.DataClasses namespaces.
  • Entity SQL: Entity SQL is a SQL-like language provided by the ADO.NET Entity Framework to support the Entity Data Model (EDM). The EDM is an extended relational model that supports basic relational concepts, rich types with inheritance, and relationships. Entity SQL supports EDM constructs, enabling users to effectively query the data represented by an entity model.
  • Entity Data Model: The Entity Data Model (EDM) is a specification for defining the data used by applications built on the Entity Framework. Applications using the EDM define entities and relationships in the domain of the application in a design schema. The design schema is used to build programmable classes used by application code. The entity data model contains of 3 parts
  1. Conceptual Schema Definition Language (CSDL): The conceptual schema is a design template for the object model that will be used by applications built on the Entity Data Model (EDM). Conceptual schema is used to declare and define entities, associations, inheritance etc. It is from this schema the Entity classes are generated.
  2. Store schema definition language (SSDL): The SSDL is a formal description of the database that persist data for an application built on the Entity Data Model (EDM). The entities and associations declared in this schema are the basis for mapping entities and associations in the conceptual schema to the corresponding entities in the storage model. This contains the metadata describing the database that persist data.
  3. Mapping specification language (MSL): In the Entity Data Model (EDM), the mapping specification uses mapping specification language (MSL) to connect the types declared in conceptual schema definition language (CSDL) to database metadata that persists data for applications that use the object model being defined.
  • LINQ to entities: LINQ to Entities enables developers to write queries against the database from the same language used to build the business logic

In In the next part of this series we will look into more details of the Entity Framework and see how Entity Framework will assist in creating data centric applications more easily.

No comments: