![Page 1: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/1.jpg)
Oliver Sturm [email protected]@devexpress.comhttp://www.sturmnet.org/blog
Oliver Sturm
Object/Relational Mapping in real-world applications
Person
XPObject
Class
Fields
name
Properties
Name
Numbers
Methods
OnDeleting
Person
PhoneNumber
XPObject
Class
Fields
number
person
Properties
Number
Person
Methods
PhoneNumber (+ 1 overload)
XPObject
XPCustomObject
Abstract Class
Properties
Oid
Methods
XPObject (+ 1 overload)
XPCustomObject
XPBaseObject
Abstract Class
Properties
IsDeleted
Methods
XPCustomObject (+ 1 overload)
![Page 2: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/2.jpg)
What is Object/Relational Mapping?
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.
![Page 3: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/3.jpg)
Why is ORM being used?
• 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
• ORM saves programmer time!
![Page 4: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/4.jpg)
Important differences
Several areas:
1. Data Binding2. Business Logic3. Multi-Tier
![Page 5: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/5.jpg)
Data Binding ADO.NET
Name City
Mike Reading
Ruth Liverpool
Sue London
Brad Birmingham
Jim Newcastle
Data
Bindin
g
DataTables, DataSets – query results
AD
O.N
ET
ORM
Data Binding?
![Page 6: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/6.jpg)
Data Binding ORM
Name City
Mike Reading
Ruth Liverpool
Sue London
Brad Birmingham
Jim NewcastleAD
O.N
ET
Fetch data
IListIBindingListITypedList...
ORM
Fetch data
![Page 7: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/7.jpg)
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.
![Page 8: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/8.jpg)
Business Logic ORM
SQL
Stored procedures (T-SQL, ...)Trigger code ...
ORM
Functionality on the serverimplemented 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.
![Page 9: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/9.jpg)
Demo
Differences between ADO.NET and ORM based applications – Data
Binding and Business Logic
![Page 10: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/10.jpg)
Where does my Business Logic live?
Several possibilities:
1.In the persistent classes themselves2.In separate classes – separate BL layer3.In the process implementations
![Page 11: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/11.jpg)
When is Business Logic executed?
More things to consider:
1.Automatically, e.g. when objects are created or saved.2.“Manually”, i.e. from a process implementation
![Page 12: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/12.jpg)
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.
![Page 13: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/13.jpg)
Important differences
Several areas:
1. Data Binding2. Business Logic3. Multi-Tier
![Page 14: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/14.jpg)
Multi-Tier with ADO.NET
Name City
Mike Reading
Ruth Liverpool
Sue London
Brad Birmingham
Jim Newcastle
Network – XML
WebServices, WCF, ...
Name City
Mike Reading
Ruth Liverpool
Sue London
Brad Birmingham
Jim Newcastle
SerializationDeserialization
Result:Identical data!
![Page 15: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/15.jpg)
Multi-Tier with ORM
• Objects contain more than just data• 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
![Page 16: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/16.jpg)
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.
![Page 17: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/17.jpg)
Demo
Tunnelling through .NET Remoting
![Page 18: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/18.jpg)
Tunnelling is not specific to Remoting
• .NET Remoting is really easy to use, as it maps all .NET data types directly
• I have examples for tunnelling through XML Web Services, WCF and RemObjects.
![Page 19: Object Relational Mapping In Real World Applications](https://reader035.vdocuments.us/reader035/viewer/2022062704/555e2e6cd8b42a384f8b58a7/html5/thumbnails/19.jpg)
Further information
• My blog: http://www.sturmnet.org/blog
• My email: [email protected]
• Commercial: http://www.devexpress.com/xpo