NHibernate Examples

11 commentsWritten on April 10th, 2011 by
Categories: NHibernate

I published some NHibernate examples almost 4 years ago, and they still get downloaded pretty frequently. Unfortunately they still use NHibernate 1.2 and are somewhat limited as to what they demonstrate. My NHibernate course is rather example/exercise-heavy so i thought it would be a good time to replace those outdated examples with new ones and make them available to anyone who wants them. The examples are not complete yet, but will be updated frequently in the next couple of weeks. After that, i intend to keep them up to date to demonstrate new NHibernate features as they are introduced with new releases. Of course, you're more than welcome to contribute examples of your own.

The solution consists of a suite of automated tests that run on a SQLite database, which demonstrate some features of NHibernate. All tests currently run with the classic HBM mapping files and FluentNHibernate. Choosing which of the two is used can be done by selecting the correct build configuration (either HBMSQLITE or FLUENTSQLITE) before running the tests. Running the tests doesn't require any software to be installed or any configuration to be performed by you. Though you can obviously run the tests on different databases if you want to. The object model that is used is based on Northwind with a couple of changes. The object model can evolve into whatever it needs to be to showcase NHibernate features/usage. Some other models might also be introduced later on to show features that wouldn't fit well with the Northwind-based model.

These examples could be useful to people who are new to NHibernate, but could be interesting for experienced NHibernate users as well, if only as a playground to quickly experiment with some features that you're unsure of.

You can find the code here or you can always download the latest version here.

  • Pingback: NHibernate Mapping Examples

  • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #831

  • http://profiles.google.com/tkmagesh77 Magesh K

    Great resource for learning NHibernate.. Thanks a lot… Including a few examples on querying will make it a complete package i guess..

    • http://davybrion.com Davy Brion

      yup, that’ll probably be added in about a week :)

  • http://profiles.google.com/stephenpatten Stephen Patten

    Thank you Davy.

    I am unable to open the database with server explorer, any ideas?

    Stephen

    • http://davybrion.com Davy Brion

      it’s a SQLite database (which doesn’t work with Server Explorer) and it gets recreated and populated with each testrun

      • http://profiles.google.com/stephenpatten Stephen Patten

        Oh, sorry I really didn’t pay to much attention to the file name, you’re right it IS the sqllite database dll, NOT the created one. I’ve used the ado.net wrapper code (http://sqlite.phxsoftware.com/) to actually connect to sqlite through server explorer once the db has been created.

        So the reason I was asking in the first place was that when trying to grok the Northwind project mapping files, it would be nice to see the actual persistance store.

        I’ve followed your blog for some time now and this is my FIRST ever experience with NHibernate.

        • http://davybrion.com Davy Brion

          ah, you can actually connect to the database during the testrun?

          • http://profiles.google.com/stephenpatten Stephen Patten

            hahaha, man I’m glad I wasn’t trying to read the data from the tables…sfiosghghdkjabhdbfa sjf 7uwr3

            Thanks again Davy. Keep the updates to Git coming

        • http://profiles.google.com/danbarua Dan Barua

          Stephen, you can use NHibernate’s Schema Export tool to build a database in SQL Server from the mappings that you can then browse at your leisure.

  • sinful bikinis

    Price is definitely an essential portion of any investment. Make specific yo don’t beat acquire and make specific to breguet classique watches retain within your budget. In situation you locate a luxurious sit back and watch that you just critically breguet pocket watch want near to one other hand it is just as well expensive, go find out identical brand brand on sale.- could possibly be the internet website protected in the event you come about for getting steering to make an make an effort to do purchase the sit back and watch online, look breguet mens watch at to ascertain Patek Phellolippe the protection and privateness attributes near to the internet site to be sure that there breguet ladies watch is not any chance of identity or details theft.breguet watches for sale /> Remember automated wrist watches possess a tendency for getting extra pricey compared to quartz sort of watches. The variation in between quartz and automated is this; Quartz assortment wrist replica Breguet Watches watches are in need of an accumulator to run and you also wholesale Breguet Watches must differ the battery when it may get weak, while Automated wrist watches run or run through your plan actions or wrist pulse.
      var _gaq = _gaq || [];  _gaq.push(['_setAccount', 'UA-13121660-3']);  _gaq.push(['_trackPageview']);
      (function() {    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;   breguet tourbillon watches  ga.src = (‘https:’ cheap Breguet Watches == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);  })();