Introduction

Topic updated 15-5-2007

To create a BO-Layer using the NHibernate framework GenWise generates the following components:

 

For each Database Repository Entity:

Business Objects
The business objects are so called POCO (Plain old C# objects) classes. These generated classes have strongly typed properties (using .NET types) based on the Database Repository table Columns (for example CustomerName property for the Customers name table column). It also generates related objects like parent references and children to the object (Orders in customers).

NHibernate XML mapping files
The XML files are automatically generated based on the meta-data stored in the DataBase repository.

Factory Classes
NHibernate Factory classes contain the actual database access methods. These methods are : fetch methods, fetch by filter methods and the CRUD methods (Create, read update and delete) .

Custom Collection classes for each Business Object
All the Get methods from the Factory return a stronly typed collection that supports most of the DataBinding interfaces defined in VS.NET 2005 DataBinding model (and in our GenWise extended DataBinding model (see related Topics).

(Optional) Dataset / Datatable class
Returns a dataset method according to your POCO structure, with the fill method you can take an existing collection and expose it through this dataset. (for instance to have a WebService return a dataset, which is a quite common scenario)

(Optional ) Unit Testing

Optional Extension Template to add unit testing to your BO layer.
Generates automatic retrieval (non-destructive) tests to make sure that you can retrieve your BO's making sure that there are no mapping errors, etc.
Makes it possible to add your own unit testing.

 

General for the Project:

NHibernate Configuration Template that allows you to configure the NHibernate configuration

Unit Testing Extension Template that allows you to add unit testing of your entire business object layer and to add your own tests.

Application Configuration Template to configure settings via an app.config file.

The power of the mapped Business Objects (BO) is that you can traverse the object relational tree in your code. The code fragment below gives an example of this. The business object for a customer with ID 12 is loaded and the orders of the customer are inspected:

 

   Northwind.CustomersFactory _ncf = new Northwind.CustomersFactory()

   Customers c = _ncf.Fetch(12);

 

   foreach (Order ord in c.Orders)

   {

       trace.Writeln(ord.order_no);

   }

 

We have made some modifications to the original NHibernate templates. NHibernate has been made part of the GenWise installation. It includes the Ms-access contribution developed at GenWise. If you want to download our modifications, you can download the source from the download section.