Friday, February 27, 2009
Speed up your Development using Ado.Net Entity Framework
This is one of my posts on the ADO.Net Entity Framework. Click here to see all my posts on Entity Framework.
Relational database systems are really considered the lifeline of every enterprise application and, in many cases, of the enterprise itself. These remarkable systems store information in logical tables containing rows and columns, allowing data access and manipulation through Structured Query Language (SQL) calls and data manipulation languages (DMLs). Relational databases are unique in the enterprise because they form the foundation from which all applications are born. In addition, unlike other software applications, databases are often shared across many functional areas of a business.
What Is ORM?
ORM is an automated way of connecting an object model, sometimes referred to as a domain model, to a relational database by using metadata as the descriptor of the object and data.
Entity Framework
The Entity Framework looks like an interesting technology which is more powerful and advanced than LINQ to SQL. Both technologies have a different kind of philosophy but several features have similar implementations. The EF is more than just an ORM (Object Relational Mapping) tool. It allows developers to query and manipulate data using a conceptual model instead of a physical storage model. It will also become the foundation of new application blocks like Astoria (ADO.NET Data Services) which will enable you to expose any data store as web services and Jasper (Data Access Incubation Projects) which can be used to build dynamic data layers.
It is important to understand that there are many benefits to using EF rather than other data access techniques. These benefits will become more evident as you work with them, but the following are the few of them.
- EF automates the object-to table and table-to-object conversion, which simplifies development. This simplified development leads to quicker time to market and reduced development and maintenance costs.
- Applications are freed from hard-coded dependencies on a particular data engine or storage schema.
- Mappings between the conceptual model and the storage-specific schema can change without changing the application code.
- Multiple conceptual models can be mapped to a single storage schema.
- Language-integrated query support provides compile-time syntax validation for queries against a conceptual model.
- EF requires less code as compared to embedded SQL, handwritten stored procedures, or any other interface calls with relational databases.
- EF provides transparent caching of objects on the client (that is, the application tier), thereby improving system performance. A good ORM is a highly optimized solution that will make your application faster and easier to support.
The ADO.NET Entity Framework is a layered framework which abstracts the relational schema of a database and presents a conceptual model.
Data Source: The bottom layer is the data which can be stored in one or many databases.
Data Providers: The data will be accessed by an ADO.NET data provider. At this moment only SQL Server is supported but in the near future there will be data providers for Oracle, MySQL, DB2, etc.
Entity Data Model (EDM): An EDM is defined by the following three model and mapping files that have corresponding file name extensions:
· Conceptual schema definition language file (.csdl) - defines the conceptual model.
· Store schema definition language file (.ssdl) - defines the storage model, which is also called the logical model.
· Mapping specification language file (.msl) - defines the mapping between the storage and conceptual models.
The Entity Framework uses these XML-based models and mapping files to transform create, read, update, and delete operations against entities and relationships in the conceptual model to equivalent operations in the data source. The EDM even supports mapping entities in the conceptual model to stored procedures in the data source.
Entity Client: EntityClient is an ADO.NET managed provider that supports accessing data described in an Entity Data Model. The mission of EntityClient is to provide a gateway for entity-level queries. Through EntityClient one queries against a conceptual model, not against a specific store implementation of that model. EntityClient does not directly communicate with the data store but it requires a separate, store-specific, provider. EntityClient employs its own language, Entity SQL. An Entity SQL query needs no change in order to work over different store implementations of the same model. That is achieved through EntityClient’s pluggable architecture. Its query pipeline compiles the Entity SQL text to a command tree that is passed to the store provider for native SQL generation.
Entity SQL (ESQL): Entity SQL is a derivative of Transact-SQL, designed to query and manipulate entities defined in the Entity Data Model. It supports inheritance and associations.
LINQ to Entities: This is a strong-typed query language for querying against entities defined in the Entity Data Model.
Summary