ORM Tools and Techniques - NHibernate - by Amin Emami

20
Amin Emami www.aminemami.com

description

This presentation is an attempt to present an overview of Object-Relational Mapping concept, with focus on:ORM ChallengesORM simplified rulesWhy persistence frameworksOverview of common features in persistence frameworksNHibernate sample code, covering all basic featuresFor more information visit http://www.aminemami.com

Transcript of ORM Tools and Techniques - NHibernate - by Amin Emami

Page 1: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emamiwww.aminemami.com

Page 2: ORM Tools and Techniques - NHibernate - by Amin Emami

• Introduction• Object Relational Mapping• Persistence Framework• Sample Code• Q&A

Amin Emami

Page 3: ORM Tools and Techniques - NHibernate - by 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

Page 4: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emami

Architectural View

Page 5: ORM Tools and Techniques - NHibernate - by Amin Emami

How do you map these classes to relational tables?

Amin Emami

Page 6: ORM Tools and Techniques - NHibernate - by 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

Page 7: ORM Tools and Techniques - NHibernate - by 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

Page 8: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emami

Page 9: ORM Tools and Techniques - NHibernate - by Amin Emami

• Let’s take a look at the sample codeo Class Diagramo POCO classes

Amin Emami

Page 10: ORM Tools and Techniques - NHibernate - by 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

Page 11: ORM Tools and Techniques - NHibernate - by Amin Emami

Some of .Net Persistence Frameworks:• NHibernate • Entity Framework• Gentle.NET• Wilson O/R • NPersist• Persistor.NET• iBATIS• Bamboo.Prevalence• etc

Amin Emami

Page 12: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emami

Page 13: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emami

Page 14: ORM Tools and Techniques - NHibernate - by Amin Emami

• Class Diagram• POCO classes• Mapping files• Configurations• Transactions

Amin Emami

Page 15: ORM Tools and Techniques - NHibernate - by 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

Page 16: ORM Tools and Techniques - NHibernate - by Amin Emami

• Database independency• Transaction management• Automatic primary key generation• Automatic dirty checking• Detached object• Concurrency• Caching

Amin Emami

Page 17: ORM Tools and Techniques - NHibernate - by Amin Emami

• Caching• Detached object• Concurrency• Interceptors• Batch processing• Attributes• Fluent Syntax• Database independency

Amin Emami

Page 18: ORM Tools and Techniques - NHibernate - by Amin Emami

• ORM Concept• Simple ORM Techniques• Persistence Frameworks• NHibernate Key Features

Amin Emami

Page 19: ORM Tools and Techniques - NHibernate - by Amin Emami

Amin Emami

Page 20: ORM Tools and Techniques - NHibernate - by 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