1 / 17

Intoduction to NHibernate

Intoduction to NHibernate. Agenda. Overview of NHibernate Models and Mappings Configuration Sessions and Transactions Queries. What is Nhibernate ?. mature, ORM solution for .NET platform free, GNU Lesser General Public License

verdi
Download Presentation

Intoduction to NHibernate

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intoduction to NHibernate

  2. Agenda • Overview of NHibernate • Models and Mappings • Configuration • Sessions and Transactions • Queries

  3. What is Nhibernate ? • mature, ORM solution for .NET platform • free, GNU Lesser General Public License • mapping an object-oriented domain model to a relational database • home == nhforge.org • files on sourceforge • groups http://groups.google.com/group/nhusers • Commercial support • hibernating rhinos - Ayende Rahien • imeta - Steve Strong, Fabio Maulo

  4. History • started as port of the popular Java O/R mapper Hibernate to .NET • Hibernate was started in 2001 by Gavin King • NHibernate was started around 2003 • ver1.0 mirrored the feature set of Hibernate 2.1 • ver1.2.1, released in 11/2007, features from Hibernate 3 and support for .NET 2.0, stored procedures, generics, and nullable types • ver 2.0 was released 08/2008. Comparable to Hibernate 3.2. .NET 1.1 • ver 3.0 - December 04, 2010 - .NET 3.5. • LINQ support, strongly typed criteria-like API called QueryOver, new AST-based parser for NHibernate'sHQL, ... • http://sourceforge.net/projects/nhibernate/files/NHibernate/

  5. Mappings • mappinga class with XML • Keys, ID generators • table-per-class hierarchy • table per class • table per concrete class • one-to-many relationship • lazy loading collections, lazy loading proxies • settingup a base entity class • handling versioning and concurrency

  6. bidirectional one-to-many class relationships • mappings enumerations • creating class components

  7. mapping a class with XML • 2x .xsd – intellisense • mapping file - XML - extension .hbm.xml • set Build Action to Embedded Resource !!! • model- collection of classes that will be persisted in the database • persistent class- any class that will be persisted (e.g. Person, Address) • entity class- a persistent class with an ID

  8. entity - an instance of an entity class • POCO- Plain Old CLR Object • POCOs are objects not burdened with inheritance or attributes needed for specific frameworks • all entity classes should be persistence ignorant • strongly held design decisions in NHibernate • Id property - primary key value from the db • persistent object identifier (POID)

  9. Persistence and the layered architecture • business layer • is responsible for implementingany business rules or system requirements that users would understand as part of the problem domain • persistence layer • group of classes and componentsresponsible for saving application data to and retrieving it from data store • defines a mapping between the business domain entitiesand the database. • NH lives here !!!

  10. Approachesto begin developing an NH application • model-first • create model -> map the model -> generate our database tables from the model and mappings • configuration-first • database-first

  11. Non-insert POID generators • assign an identity to a persistent object without writing the object's data to the db • hilo • guid • guid.comb • guid.native • uuid.hex, uuid.string • counter, increment • sequence, seqhilo

  12. Post-insert POID generators • require data to be persisted to the database for an ID to be generated • identity • select (uses natural id) • sequence-identity • trigger-identity • native

  13. table-per-class hierarchy • data for our entire hierarchy is stored in a single table • discriminator column ProductType • distinguish among products, books, and movies • by default, the contains the class name • Eg.Core.Product, Eg.Core.Book, or Eg.Core.Movie • subclass properties as must be nullable • suggested method for mapping class hierarchies

  14. table-per-class • properties of the base class in a shared table • each subclass gets its own table • joined-subclasselement • key element to name the primary key column

  15. table-per-concrete class • each class gets its own table • containing columns for all properties of the class and the base class • there is no duplication of data • union-subclass element

More Related