This example will show how NHibernate.Burrow and NHibernate.Burrow.AppBlock simplifies ASP.NET/NHibernate application development on a day-to-day basis. The full code is available in NHContrib/src/NHibernate.Burrow/examples/BasicThreeTier.
This simple example is about managing an entity called "Customer".
The mapping file as follows
The first step will be creating a DAO for it. Here we create one by inheriting the DAO base from NHibernate.AppBlock
The DAO base class provides a lot of functions including CRUD and much more. But this inheritance is by no means mandatory. You can always use your own DAO.
Now the domain layer is ready. Let's create a page that lists all the all the customer entities in a grid view that is sortable and paged (both at DB side).
The EditCustomer1 is a user control that we created to edit one customer, we'll talk about it later.
The code behind may look like an excerpt, but it's not. It's just simple as that, we have a paged and sortable (both at Database side) gridview that lists all customers. The inherited DAO together with the ObjectDataSource take care of all the tedious work of the DB side sorting and paging. In the code behind, we only need two simple methods for binding the selected customer to the EditCustomer control and refresh the gridview when customer is modified in that control.
Now let's look at the EditCustomer user control.
The wwDataBinder here is an optional 3rd party control that realizes Two-way databinding between UI controls and properties of the code behind class. This wonderful control is created by Rick Strahl. It eliminates the code that transfer values between form control values and entity properties. Detailed information about it can be found here. Again, this control is not mandatory by NHibernate.Burrow.
Now let's look at the code behind.
Again, this is the complete code that is necessary to manage all the properties for the customer entity.
Now with the code listed here we created a three tier application that can list and manage all the customers in DB. As you can see here, the code is very straightforward and clean. No DB related management code anywhere, not even NHibernate is mentioned.
This example demonstrated that other than the advanced features, such as conversation, it provides, NHibernate.Burrow also greatly frees the developers from DB/NHibernate related concerns and thus enable them to focus mostly on project vised logic in their day-to-day development.