ORM vs. CQRS/ES throwdown – Part 3 – The Database

Next up… the MsSql 2008 database structure.  If we’re building a typical n-tier application with ORM, we need the “R” – the Relational Database in this mix.  This is in preparation for the construction of an NHibernate data access layer (DAL).  If you are like me, when it comes to building an application, the first thing you design out is what and how we’re going to store these objects.

First up, define the Product table:

I’m a stickler for sql scripts to be idempotent, as this format allows me to re-run the script as many times as my paranoid mind thinks I need to.  I also prefer to format sql by adding PRINT statements to report to me or my support personnel exactly what the script performed.

The corresponding Evaluation table looks like this:

At this point, we are 29 lines of OUR code into storing our data.  We can stop here in our database, as our ORM tools have facilities to generate appropriate commands to select, insert, update, and delete data from these tables.

In our next post, I’ll document the creation of a simple NHibernate repository using an existing Sql 2008 Express database.  We’ll cut some c-sharp, some hbm.xml files, and maybe just maybe a unit test or two.