NHibernate Templates - VB

Table of Contents

Overview

These are a collection of templates that generate code that use NHiberate Framework.

These templates are designed to produce 5 major things...

  1. NHibernate XML mapping files.
  2. Business objects to match the NHibernate maps.
  3. A Manager object for each business object that provide table specific access methods.
  4. A NHibernateSessionManager that produces NHibernateSession objects to help abstract NHibernate ISession logic.
  5. Very basic unit tests for each business object/manager.

Note: To make assign a custom name to either a column or table, add a "cs_alias" value to it's extended properties.

Quick Start

  1. Create a new VisualStudio project.
  2. Set the project Root Namespace to be blank.
  3. Add a new CodeSmith Project (CSP) to your project.
    1. Right click on the project.
    2. Select "Add new item..."
    3. In Common Items there will be a CodeSmith Project.
  4. Add NHibernateMaster.cst to your CSP's output.
  5. Configure NHibernateMaster as desired.
    1. Don't forget to update your Assembly name!
  6. Create/Update your App.Config to support NHibernate (example below).
    1. If using the sample below, update the connection string and...
    2. ...update the mapping assembly.
  7. Right click on your CSP and Generate Outputs.
  8. Compile, and enjoy!

Sample App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string"></property>
      <mapping assembly="NHibernate.Generated"/>
    </session-factory>
  </hibernate-configuration>
</configuration>

Dependancies

These templates will only build with CodeSmith 5.0.

These templates include NHibernate version 2.0.0.Alpha1; but they can also support NHibernate 1.2.1
NHibernate 1.2.1 Differences:

  1. Supports legacy Namespaces.
  2. UnitTests validate deleted rows differently.

These templates linclude NUnit 2.4.7 for .Net 2.0

These templates support both Visual Studio 2008 and 2005.
Visual Studio 2005 Differences:

  1. Does not include partial methods in business ojects.

Known Issues

Downloads

Download the latest release from GoogleCode.

History

*Breaking change

Links

NHibernate for .NET

NUnit

Special Thanks

Billy McCafferty
Ayende @ Rahien
NHibernate in Action