SlideShare a Scribd company logo
NHibernateby Andriy Buday
OutlineQ1: What is NHibernate?Q2: Why do I need it?Q3: How does it look like?ConceptsDEMO 1: Hello World!Q4: How can I proceed with it?QueriesMore about mapping, querying, usage patternsDEMO 2: Customer-Orders-Productshttp://andriybuday.blogspot.com/Let see… will we get what we want!
Q1: What is NHibernate?NHibernate is…ORMNew level of Abstractionhttp://andriybuday.blogspot.com/Paradigm mismatch
Q2: Why Do I need it?Because…http://andriybuday.blogspot.com/Development speed increasesReducing database workOptimizes access to DB, so could even perform better than plain ADO.NETYou think in terms of business model, not databaseMore time for real programming
Q2: Why Do I need it?Why do I like NHibernate?http://andriybuday.blogspot.com/MatureFree & Open SourceGood community supportFlexibleAllows you do Domain Driven DesignYou asked for comparison with other ORM…LINQ to SQL doesn’t really lead you to good modelsEntity Framework has better Linq and it is MicrosoftVisit http://ormbattle.net/ for performance numbersGoogle.Search(string.Format“Nhibernate vs. {0}”, yourORM);
Q3: How does it look like?Concepts: Unit of Workhttp://andriybuday.blogspot.com/Kind of “workspace” within which you can do anything you wantA Unit Of Work either success or fails as a unitConceptually like database transactionsIn NHibernate we have ISession which does the sameConceptually we have the same for in ADO.NET as DataSet
Q3: How does it look like?Concepts: ISessionhttp://andriybuday.blogspot.com/Open a sessionWe get it from the session factoryWe do some workSession.Add(…)Session.Delete(…)Commit the sessionSession.Flush(…)
Q3: How does it look like?Concepts: ISessionFactoryhttp://andriybuday.blogspot.com/We are getting our session through this classVery expensive to createOne per database or application
Q3: How does it look like?Concepts: Summaryhttp://andriybuday.blogspot.com/Configuration Class builds Session FactorySession Factory builds SessionSession is used as Unit Of Work to interaction with objects and persist to underlying databasevar sessionFactory = newConfiguration().Configure().BuildSessionFactory();      using (var session = sessionFactory.OpenSession()){var customer = newCustomer();    session.SaveOrUpdate(customer);    session.Flush(); }
Q3: How does it look like?Architecture: and look from inside?http://andriybuday.blogspot.com/
Q3: How does it look like?DEMO: Hello World!http://andriybuday.blogspot.com/Just basics… to refresh our minds 
Q4: How can I proceed with it? More on Query APIhttp://andriybuday.blogspot.com/Criteria APIObject oriented queryingICriteria chainingEasy to writeHard to readHQL APIString basedParameterizedSimilar to SQLSpeak in terms of ObjectsMore flexible“from Customer c wherec.FirstName = :firstName”session.CreateCriteria(typeof(Customer))    .Add(Restrictions.Eq("FirstName", "Hello"))
Q4: How can I proceed with it? Mappinghttp://andriybuday.blogspot.com/<hibernate-mappingxmlns="urn:nhibernate-mapping-2.2"default-lazy="true"assembly="LearningNHibernate"namespace="LearningNHibernate">  <classname="Customer"table="Customer"xmlns="urn:nhibernate-mapping-2.2">    <idname="CustomerId"column="CustomerId"type="Int32">      <generatorclass="identity" />    </id>    <propertyname="FirstName"column="Firstname"length="50"type="String">      <columnname="Firstname" />    </property>    <propertyname="LastName"column="Lastname"length="50"type="String">      <columnname="Lastname" />    </property>  </class></hibernate-mapping>publicclassCustomerMap : ClassMap<Customer>    {public CustomerMap()        {            WithTable("Customer");            Id(x => x.CustomerId);            Map(x => x.FirstName, "Firstname");            Map(x => x.LastName, "Lastname").WithLengthOf(50);        }    }
Q4: How can I proceed with it? Fetch strategieshttp://andriybuday.blogspot.com/Lazy loadingDefault for all collectionsMembers are loaded from database when assessedUsually good for performanceSession has to stay OPENEager FetchingUse when you sure you’ll use dataOUTER joins
Q4: How can I proceed with it? Caching, batching, concurrencyhttp://andriybuday.blogspot.com/First level cacheFollowing will run only one SELECTSecond level cacheWithin two sessions you still run one SELECTIt is needed to explicitly turn it on everywhereBatch processing<property name="adonet.batch_size">250</property>Concurrency<version name="Version" column="Version"/> var customer1 = session.Get<Customer>(5);var customer2 = session.Get<Customer>(5);
Q4: How can I proceed with it?http://andriybuday.blogspot.com/Use FluentNhibernate to do not bore developers with XMLCreate wrappers to have NHibernateRepositoryImplement UnitOfWorkVS projectsTwo ways for kick-offFrom database to ObjectsFrom objects to Database
DEMO 2: Mapping, Querying, LazyLoad, etc..http://andriybuday.blogspot.com/Damn it! Let’s write some code again!
Read blog! Follow me! Visit LVIV .NET UG!http://andriybuday.blogspot.com/http://andriybuday.blogspot.com/@andriybudayandriybuday@gmail.comhttp://dotnetug-lviv.blogspot.com/
Linkshttp://andriybuday.blogspot.com/My blog:http://andriybuday.blogspot.comLviv .NET User Group:http://dotnetug-lviv.blogspot.com/NHibernate:Home Page: http://nhibernate.com/Reference: http://www.nhforge.org/doc/nh/en/index.htmlGreat series of screencasts on NHibernate:http://www.summerofnhibernate.com/ORM with NHibernate screen cast (2 hours)http://www.flux88.com/uploads/ORMWithNHibernateScreenCast.wmvTools:Profiler: http://nhprof.com/Fluent NHibernate: http://fluentnhibernate.org/MyGeneration: http://www.mygenerationsoftware.com/

More Related Content

PPTX
To build a WordPress Theme: Wordcamp Denmark 2014
PDF
Web Development Tutorial Workshop for Beginners - Learn Responsive Web Design...
PDF
Responsive Web Design Tutorial PDF for Beginners
PDF
What is new in Angular 2.0
PPTX
Development Application for Windows 8 by Eugene Kiriyan
PDF
.NET MicroFramework by Yulian Slobodyan
PPT
Modern mobile development overview
PPTX
Mobile for JS Developer
To build a WordPress Theme: Wordcamp Denmark 2014
Web Development Tutorial Workshop for Beginners - Learn Responsive Web Design...
Responsive Web Design Tutorial PDF for Beginners
What is new in Angular 2.0
Development Application for Windows 8 by Eugene Kiriyan
.NET MicroFramework by Yulian Slobodyan
Modern mobile development overview
Mobile for JS Developer

Similar to Lviv .Net User Group. NHibernate (20)

DOC
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
PPTX
NHibernate for .NET
PPTX
NHibernate
PPT
Introduction to NHibernate
PDF
Nhibernate Part 2
PPTX
NHibernate for .NET
PPTX
NHibernate from inside
PDF
Nhibernate Part 1
DOCX
Hibernate3 q&a
PPT
Hibernate for Beginners
PPT
Hibernate Session 1
DOC
OR Mapping- nhibernate Presentation
PPTX
Hibernate tutorial
PPTX
nHibernate Caching
PDF
Hibernate ORM: Tips, Tricks, and Performance Techniques
PDF
Hibernate interview questions
ODP
Hibernate complete Training
PDF
Hibernate reference1
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
NHibernate for .NET
NHibernate
Introduction to NHibernate
Nhibernate Part 2
NHibernate for .NET
NHibernate from inside
Nhibernate Part 1
Hibernate3 q&a
Hibernate for Beginners
Hibernate Session 1
OR Mapping- nhibernate Presentation
Hibernate tutorial
nHibernate Caching
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate interview questions
Hibernate complete Training
Hibernate reference1
Ad

More from Dima Maleev (13)

PDF
PPTX
JavaScript in Mobile Development
PPTX
Fear and Loathing at PhoneGap
PPTX
Development Applications for Chrome OS
PDF
Gamification
PPTX
Go mobile with Windows Phone
PPTX
Time. To manage, or not to manage
PPTX
Parallel extensions in .Net 4.0
PPTX
Создание SharePoint 2010 решений в Visual Studio
PPTX
24000 Days Of UX
PPTX
Developing silverlight applications for windows phone 7 series
PPT
New Features Of ASP.Net 4 0
PPT
Microsoft Azure
JavaScript in Mobile Development
Fear and Loathing at PhoneGap
Development Applications for Chrome OS
Gamification
Go mobile with Windows Phone
Time. To manage, or not to manage
Parallel extensions in .Net 4.0
Создание SharePoint 2010 решений в Visual Studio
24000 Days Of UX
Developing silverlight applications for windows phone 7 series
New Features Of ASP.Net 4 0
Microsoft Azure
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Big Data Technologies - Introduction.pptx
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Lviv .Net User Group. NHibernate

  • 2. OutlineQ1: What is NHibernate?Q2: Why do I need it?Q3: How does it look like?ConceptsDEMO 1: Hello World!Q4: How can I proceed with it?QueriesMore about mapping, querying, usage patternsDEMO 2: Customer-Orders-Productshttp://andriybuday.blogspot.com/Let see… will we get what we want!
  • 3. Q1: What is NHibernate?NHibernate is…ORMNew level of Abstractionhttp://andriybuday.blogspot.com/Paradigm mismatch
  • 4. Q2: Why Do I need it?Because…http://andriybuday.blogspot.com/Development speed increasesReducing database workOptimizes access to DB, so could even perform better than plain ADO.NETYou think in terms of business model, not databaseMore time for real programming
  • 5. Q2: Why Do I need it?Why do I like NHibernate?http://andriybuday.blogspot.com/MatureFree & Open SourceGood community supportFlexibleAllows you do Domain Driven DesignYou asked for comparison with other ORM…LINQ to SQL doesn’t really lead you to good modelsEntity Framework has better Linq and it is MicrosoftVisit http://ormbattle.net/ for performance numbersGoogle.Search(string.Format“Nhibernate vs. {0}”, yourORM);
  • 6. Q3: How does it look like?Concepts: Unit of Workhttp://andriybuday.blogspot.com/Kind of “workspace” within which you can do anything you wantA Unit Of Work either success or fails as a unitConceptually like database transactionsIn NHibernate we have ISession which does the sameConceptually we have the same for in ADO.NET as DataSet
  • 7. Q3: How does it look like?Concepts: ISessionhttp://andriybuday.blogspot.com/Open a sessionWe get it from the session factoryWe do some workSession.Add(…)Session.Delete(…)Commit the sessionSession.Flush(…)
  • 8. Q3: How does it look like?Concepts: ISessionFactoryhttp://andriybuday.blogspot.com/We are getting our session through this classVery expensive to createOne per database or application
  • 9. Q3: How does it look like?Concepts: Summaryhttp://andriybuday.blogspot.com/Configuration Class builds Session FactorySession Factory builds SessionSession is used as Unit Of Work to interaction with objects and persist to underlying databasevar sessionFactory = newConfiguration().Configure().BuildSessionFactory(); using (var session = sessionFactory.OpenSession()){var customer = newCustomer(); session.SaveOrUpdate(customer); session.Flush(); }
  • 10. Q3: How does it look like?Architecture: and look from inside?http://andriybuday.blogspot.com/
  • 11. Q3: How does it look like?DEMO: Hello World!http://andriybuday.blogspot.com/Just basics… to refresh our minds 
  • 12. Q4: How can I proceed with it? More on Query APIhttp://andriybuday.blogspot.com/Criteria APIObject oriented queryingICriteria chainingEasy to writeHard to readHQL APIString basedParameterizedSimilar to SQLSpeak in terms of ObjectsMore flexible“from Customer c wherec.FirstName = :firstName”session.CreateCriteria(typeof(Customer)) .Add(Restrictions.Eq("FirstName", "Hello"))
  • 13. Q4: How can I proceed with it? Mappinghttp://andriybuday.blogspot.com/<hibernate-mappingxmlns="urn:nhibernate-mapping-2.2"default-lazy="true"assembly="LearningNHibernate"namespace="LearningNHibernate">  <classname="Customer"table="Customer"xmlns="urn:nhibernate-mapping-2.2">    <idname="CustomerId"column="CustomerId"type="Int32">      <generatorclass="identity" />    </id>    <propertyname="FirstName"column="Firstname"length="50"type="String">      <columnname="Firstname" />    </property>    <propertyname="LastName"column="Lastname"length="50"type="String">      <columnname="Lastname" />    </property>  </class></hibernate-mapping>publicclassCustomerMap : ClassMap<Customer> {public CustomerMap() { WithTable("Customer"); Id(x => x.CustomerId); Map(x => x.FirstName, "Firstname"); Map(x => x.LastName, "Lastname").WithLengthOf(50); } }
  • 14. Q4: How can I proceed with it? Fetch strategieshttp://andriybuday.blogspot.com/Lazy loadingDefault for all collectionsMembers are loaded from database when assessedUsually good for performanceSession has to stay OPENEager FetchingUse when you sure you’ll use dataOUTER joins
  • 15. Q4: How can I proceed with it? Caching, batching, concurrencyhttp://andriybuday.blogspot.com/First level cacheFollowing will run only one SELECTSecond level cacheWithin two sessions you still run one SELECTIt is needed to explicitly turn it on everywhereBatch processing<property name="adonet.batch_size">250</property>Concurrency<version name="Version" column="Version"/> var customer1 = session.Get<Customer>(5);var customer2 = session.Get<Customer>(5);
  • 16. Q4: How can I proceed with it?http://andriybuday.blogspot.com/Use FluentNhibernate to do not bore developers with XMLCreate wrappers to have NHibernateRepositoryImplement UnitOfWorkVS projectsTwo ways for kick-offFrom database to ObjectsFrom objects to Database
  • 17. DEMO 2: Mapping, Querying, LazyLoad, etc..http://andriybuday.blogspot.com/Damn it! Let’s write some code again!
  • 18. Read blog! Follow me! Visit LVIV .NET UG!http://andriybuday.blogspot.com/http://andriybuday.blogspot.com/@andriybudayandriybuday@gmail.comhttp://dotnetug-lviv.blogspot.com/
  • 19. Linkshttp://andriybuday.blogspot.com/My blog:http://andriybuday.blogspot.comLviv .NET User Group:http://dotnetug-lviv.blogspot.com/NHibernate:Home Page: http://nhibernate.com/Reference: http://www.nhforge.org/doc/nh/en/index.htmlGreat series of screencasts on NHibernate:http://www.summerofnhibernate.com/ORM with NHibernate screen cast (2 hours)http://www.flux88.com/uploads/ORMWithNHibernateScreenCast.wmvTools:Profiler: http://nhprof.com/Fluent NHibernate: http://fluentnhibernate.org/MyGeneration: http://www.mygenerationsoftware.com/

Editor's Notes

  • #2: Hello,Lviv .NET User Group!
  • #4: Hibernate&apos;s goal is to relieve the developer from 95 percent of common data persistence related programming tasks, compared to manual coding with SQL It handles persisting plain .NET objects to and from an underlying relational database.Nhibernate is an abstraction layer at the top of you database.
  • #6: It is matureCommunity…Get answers quickly…Has definite path…Have community feedback
  • #12: This should be simple app… maybe console..I’m going to show few inserts including message “Hello World!” Good to show Nprof in action with this
  • #13: Todo: add code samples