ORM Tools and Techniques - NHibernate - by Amin Emami
-
Upload
amin-emami -
Category
Documents
-
view
143 -
download
1
description
Transcript of ORM Tools and Techniques - NHibernate - by Amin Emami
Amin Emamiwww.aminemami.com
• Introduction• Object Relational Mapping• Persistence Framework• Sample Code• Q&A
Amin Emami
• Director of Information Technology• 10 Years of Enterprise Software
Development• Using Persistence Frameworks since
2001o EJB (Java): 2001o Hibernate (Java): 2004o NHibernate (.Net): 2005o Entity Framework: 2009
Amin Emami
Amin Emami
Architectural View
How do you map these classes to relational tables?
Amin Emami
• Object-Oriented: Everything is an object• Objects vs. Tables: ODBMS?• OO features• Object Types vs. DB Types• CRUD to/from database• Objects vs. tabular data• Managed Code
Amin Emami
• A technique to map the classes and the tables• Simplified rules
o Table per main objecto No FK, use object referenceo One-to-many relationso Association table for many-to-many relationso In a one-to-one relation, all the fields go to one
main tableo Inheritance mapping strategies
Tale per class hierarchy Table per concrete class
Amin Emami
Amin Emami
• Let’s take a look at the sample codeo Class Diagramo POCO classes
Amin Emami
• ORM library, providing a framework foro Mapping an object-oriented domain model to
relational databaseo High level persistence object handling
functions
Amin Emami
Some of .Net Persistence Frameworks:• NHibernate • Entity Framework• Gentle.NET• Wilson O/R • NPersist• Persistor.NET• iBATIS• Bamboo.Prevalence• etc
Amin Emami
Amin Emami
Amin Emami
• Class Diagram• POCO classes• Mapping files• Configurations• Transactions
Amin Emami
• Better object-oriented• Collection Mapping• Basic queries and object persistence is
handled by the framework• Object query language instead of SQL,
doing more complex queries• Lazy loading
Amin Emami
• Database independency• Transaction management• Automatic primary key generation• Automatic dirty checking• Detached object• Concurrency• Caching
Amin Emami
• Caching• Detached object• Concurrency• Interceptors• Batch processing• Attributes• Fluent Syntax• Database independency
Amin Emami
• ORM Concept• Simple ORM Techniques• Persistence Frameworks• NHibernate Key Features
Amin Emami
Amin Emami
• You are free:o to Share―to copy, distribute and transmit the worko to Remix―to adapt the work
• Under the following conditionso Attribution. You must attribute the work in the manner specified
by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
• Nothing in this license impairs or restricts the author’s moral rights.
• For more information see http://creativecommons.org/licenses/by/3.0/
Amin Emami