Object/Relational Mapping (ORM) is a technique that allows programmers to map fields and properties of classes to fields in relational database tables, and vice versa, in order to store object data in relational databases.
Data Binding ADO.NET Data Binding DataTables, DataSets – query results ADO.NET ORM Data Binding? Name City Mike Reading Ruth Liverpool Sue London Brad Birmingham Jim Newcastle
Data Binding ORM ADO.NET Fetch data IList IBindingList ITypedList ... ORM Fetch data Name City Mike Reading Ruth Liverpool Sue London Brad Birmingham Jim Newcastle
Business Logic ADO.NET SQL Stored procedures (T-SQL, ...) Trigger code ... ADO.NET, SQL code Functionality Functionality Functionality must be implemented in different models, using different programming languages.
Business Logic ORM SQL Stored procedures (T-SQL, ...) Trigger code ... ORM Functionality on the server implemented in .NET ORM leverages existing knowledge and skills related to OO programming and unifies the programming model ORM can provide a level of abstraction towards the database Functionality Functionality Functionality is implemented in the same model, using the same programming language.
Automatically, e.g. when objects are created or saved.
“ Manually”, i.e. from a process implementation
Important for Business Logic! Expectations regarding data consistency could be different when ORM is being used: suddenly data has to be consistent even if it lives “only” in RAM! Whether or not this is relevant for you depends on your use case.
Multi-Tier with ADO.NET Network – XML WebServices, WCF, ... Serialization Deserialization Result: Identical data! Name City Mike Reading Ruth Liverpool Sue London Brad Birmingham Jim Newcastle Name City Mike Reading Ruth Liverpool Sue London Brad Birmingham Jim Newcastle
The ORM system does a lot of management work for us, and so it has certain expectations about status.
Consequence: Communication must be designed to consider ORM requirements
Multi-Tier with ORM Dynamic SQL Network Metadata Transport format Transport format / SQL Persistent Classes / Query classes / Transport format Persistent Classes Layer Data used ORM Optional! Application The application works with persistent classes and calls functionality of the ORM system. On this layer, the ORM system provides most of its services – Identity Map, Transaction handling, ... The transport format defines Data Transfer Objects (DTOs). This layer is optional – it’s used when “Dynamic SQL” is a separate tier. Finally the ORM system dynamically generates SQL code.