Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

NHibernate ASP.NET Sample for Visual Studio 2005

I’ve updated my NHibernate sample application to use NHibernate 1.0, Visual Studio 2005, and SQL Server 2005.

It’s available for download here.  I’m working on writing a custom membership provider using NHibernate but for now the login is hard-coded.  The user name is “admin” and the password is “password”. 


Update (11/5/2005): In order to avoid having to distribute a SQL database backup, I added a “create schema“ page to the sample app.  This page uses the “hbm2dll“ features of NHibernate.  Click on the “Create Schema“ link in the app and follow the on screen directions. 

I also figured out that some of the freakiness that people have been having getting this going had to do with different beta versions of the VS2005 and Framework 2.0.  I completely scrapped the previous .sln and .csproj files that I was using before and re-created them with the release version of VS2005. 

(NOTE: Thanks to Bob Pardoe for his help in working out the kinks of this sample.) 

Update (11/3/2005): Based on feedback I’ve gotten, I’ve reworked the sample a little for ease of deployment.  I hadn’t realized how much extra junk was hanging around in those file folders.  I removed a lot of non-relevant source files and now everything is contained in a single zip.  You should be able to unzip the file and load up the .sln file without having to mess with references.  (Let me know if that’s not the true.)


  • bugtracker_db_20051022.bak – This is the SQL2005 database that I’m using as the back end.  Create a database called “bugtracker“ and restore this database backup. 
  • Com.Benday.BugTracker.WebUI – This is the folder for the user interface.  The start page should be set to “login.aspx“.  The two pages that use nhibernate are ListProjects.aspx and EditProject.aspx.  In web.config, check out the section for figuring out how to handle nhibernate session management. 
  • Com.Benday.BugTracker.BusinessFacade: Facade layer.  Not too much happening here.  This would be a good place for validation logic if you want to avoid Lifecycle calls.
  • Com.Benday.BugTracker.Business: This is the domain (aka entity / business object) project.  This is where the persistent classes are defined and the nhibernate mappings are stored.
  • Com.Benday.BugTracker.DataAccess: Data access layer.  Talks to nhibernate.  This is also where I put the NHibernateHttpModule.  NHibernateHttpModule handles all the nhibernate configuration, session factory and session management.  Even though it’s an HttpModule, it is built to work in a non-ASP.NET environment (winforms app, console app).  Also, check out SchemaUtility.cs for the hbm2dll schema create code.


, ,

One response to “NHibernate ASP.NET Sample for Visual Studio 2005”

  1. Shrikant Avatar

    I am getting an error: NHibernate.MappingException: Could not compile the mapping document: Hibernate.nhBroker.hbm.xml —> NHibernate.MappingException:
    persistent class Hibernate.nhBroker, Hibernate not found…. I have created a 2.0 project which has both hbm.xml file and the entity class.

    Any solutions are welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.