Thursday, 22 September 2011

Mapping by Code - Part 1

Over the next few weeks I am going to put together a sample application showing how you would build a project using Mapping by code. Why do this? Well firstly there are not too many examples on the web yet about NHibernate 3.2 and mapping by code and secondly I am running out of Blog ideas :)

The domain I shall use will based on events, that is events that people pay to book on to. I have vastly simplified the domain so that it looks like this:-


This is where events are held, a typical event would be "Developers Forum" or "How to get ahead in business" etc. The event has a name and a time it starts and finishes.

Event Package

This table holds the different packages that a visitor can book. For example a package could be:-
"Gold" - you get a better seat and a cup of tea
"Silver" - you get a seat but no tea
"Bronze" - you are forced to stand

Event Visitor

As you can see this table holds the people who are attending. A visitor can book more than one ticket so I have decided to use a hierarchical structure, that is the person who books has a ParentId of NULL and the additional people he/she books on will get a Id in ParentId.

Event Payment

This table just keeps track of who has paid. Notice that I have denormalised this table a bit and have created a column called NoTickets sold.

Please note that this domain is for demonstration purposes as I just wanted to show how hierarchical structures can be used in NHibernate.

Next post will be how we create a C# project to map this domain

No comments:

Post a Comment