Tech Brief

ADO.NET Entity Framework

The new object/relational mapping technology in 'Orcas.'

Relational databases aren't designed to make programming against them easier, but to ensure performance, data consistency and concurrency. Seldom do developers work directly with data in the form that is returned from a database.

Proprietary data access layers retrieve and transform data accessed in a store into business objects. But when the underlying database changes, these layers must adapt to process the changes.

ADO.NET Entity Framework uses abstraction to scrub out complexity at the logical database layer, with a set of data access APIs in the .NET Framework 3.5 and corresponding tools in Visual Studio, code-named "Orcas."

ADO.NET is a data-access, .NET-integrated technology that enables applications to connect to and manipulate data. The ADO.NET Entity Framework will build on top of the existing ADO.NET 2.0 provider model, which enables access to myriad databases. The Entity Framework will be included in Orcas beta 1.

The ADO.NET Entity Framework brings to life the Entity Relationship Model (ER Model) that many database developers have used, for 30 years, to capture and diagram conceptual models of data, prior to mapping this information into a final logical -- or relational-model. The Entity Framework implements the ER Model in the form of the Entity Data Model (EDM), maintaining the principle concepts of Entities and Relationships as first-class data types, and allowing developers to program against the same conceptual model or business logic that was used in design.

Entity Data Model
The EDM is constructed largely of EntityTypes and Associations. Consider an application that controls inventory for a wine collector. To relate back to the ER Model, each Entity [Wine, Winery] from the ER Diagram becomes an EntityType with instances of each EntityType contained in EntitySets, and each Relationship [Wine produced by Winery] from the ER Diagram becomes an Association with instances of each Association contained in an AssociationSet. Associations maintain the same connectivity [1:1, 1:many] as in the ER Diagram, and the Attributes [Sweetness, Year, Size] from the ER Diagram become Properties in the EDM that describe each EntityType. The EDM also allows for inheritance between EntityTypes and for an EntityType to define NavigationProperties, encapsulating the functionality of the database "link table," describing how to navigate from one EntityType to another by way of an Association.

Schemas & Mapping
The Entity Framework uses three XML schema files, the CSDL, SSDL and MSL, to describe the Conceptual Model, the logical Storage Schema and the Mapping, respectively. These files can be coded manually, generated automatically from an existing relational database by the EDM wizard in Visual Studio, or generated automatically by an EDM Designer that was previewed in March at VSLive!.

The CSDL describes the EDM, including the EntitySets, EntityTypes, Associations and AssociationSets that have been defined.

The SSDL describes the tables and columns, which map to the Entities and Relationships chosen for the EDM, as they exist in the associated relational database. By limiting the tables and columns described in the SSDL, it is possible to provide a client-side view of the database different from the actual View or Database being accessed.

Finally, the MSL describes how the Entity Framework maps between the Conceptual Model of the EDM (CSDL) and the logical Storage Schema (SSDL) of the database.
The layering of the three XML schema files allows a separation between code and data, ensuring that the database schema may be changed, and the application will continue to run, with only a simple update of the mapping files.

Using the Entity Framework
Previously with ADO.NET, data from the relational database was accessed using a store-specific provider, such as SQLClient. Entity Framework introduces EntityClient, which allows for entity-level queries against the EDM and a new Object Services layer allowing developers to interact (CRUD) with Entities, as CLR objects, through LINQ to Entities extensions to VB 9.0 or C# 3.0, or a new extension to SQL called Entity SQL. EntityClient acts as the bridge between the Entity Framework and the .NET data provider such as SQLClient or Oracle data provider.

EntityClient follows the same pattern as other existing ADO.NET providers, making available EntityConnection, EntityCommand and EntityDataReader, and allowing developers to retrieve Entities directly with Entity SQL queries without using the Object Services layer.

The EDM and Entity Framework allow developers to program against a conceptual domain model rather than directly against a relational database. By separating code and data, developers can write less code when manipulating data.
comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube