Presentation is loading. Please wait.

Presentation is loading. Please wait.

NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27

Similar presentations

Presentation on theme: "NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27"— Presentation transcript:

1 NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27

2 Object/Relational Mapping (ORM) Persistence technique Allows Object-Oriented Programming Supports Relational Database Enables many positive design principles: ◦ Separation of concerns ◦ Domain Driven Development ◦ Test Driven Development

3 NHibernate ORM library implemented using.NET Port of the Java library called Hibernate Database-independent (almost) Provides most advanced features Free, open source and mature

4 Persistence Make data outlives the execution of the program that created it Commonly known as CRUD operations CRUD = Create, Retrieve, Update, Delete Manipulates entities in an object-oriented language Data persisted in tables of a relational database

5 Entity Object-oriented class (inheritance and polymorphism) Encapsulates fields using properties Use methods to implement business logic No constraint on the structure (DataSet is not an entity) Effective tools for software engineering

6 Table Set of data Contains columns and rows Supports the relational algebra Effective tools for data manipulation

7 Entities are best for modeling a business domain

8 Tables are best for efficient persistence

9 NHibernate Configuration Process Provide information: ◦ Database connection details ◦ Entities mapping Auto generate the database tables with one line of code Use a NHibernate session to access the database: using(ISession session = sessionFactory.OpenSession()) using(session.BeginTransaction()) { // Use NHibernate here session.Transaction.Commit(); } Mapping of entities to tables Using.NET attributes: [Class] public class Animal { [Id(Name="Id")] [Generator(1, Class="native")] public int Id { get; set; } [Property] public string Name { get; set; } }

10 Object/Relational Mapping brings the best of both worlds Save entities (Object-oriented; no SQL!) var eagle = new Animal(2, "Eagle", "2 paws", "2 wings"); nhibernateSession.Save(eagle); Load entities var eagle = nhibernateSession.Get (2); Using queries ◦ HQL: Hibernate Query Language ◦ QBC: Query by Criteria ◦ Linq for NHibernate (in beta)

11 Linq for NHibernate Language Integrated Query (LINQ) “Adds native data querying capabilities to.NET languages using a syntax reminiscent of SQL” var result = from lb in _session.Linq () where lb.Name.Contains("e") orderby lb.Name select lb; Potentially faster than hand-coded SQL commands due to caching, batching, lazy loading and other performance optimizations.

12 To Learn More NHibernate Website: NHibernate Resources: NHibernate in Action: NHibernate Forum:

Download ppt "NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27"

Similar presentations

Ads by Google