SnCore!

Data (Puzzle and NHibernate)

Introduction

This page will guide you through the SnCore data development process. It's really easy and powerful.

Prerequisites

  • Microsoft SQL Server 2005
  • Puzzle Framework (ObjectMapper)

SQL Server 2005

This is where everything starts. Think 100% object oriented approach. To create a new concept you must first create a new table. This is typically done in Enterprise Manager. There're a few rules of thumb.

  1. There must be an automatic Id to every table with a primary key.
  2. Unique keys are named UK_.
  3. Foreign keys cascade delete in most cases.

After you create new tables, export the database schema to src/SnCore.Data/SnCoreSqlServer.sql from the SnCore.Data directory and the SnCore.Data.Script.exe program.

c:\source\sncore\sncore.data > ..\SnCore.Data.Script\bin\Debug\SnCore.Data.Script.exe
Processing 112 tables ...
Server[@Name='DBLOCK-GREEN']/Database[@Name='SnCore']/Table[@Name='Account' and @Schema='dbo']
...

Puzzle Framework and ObjectMapper

SnCore uses a tool called ObjectMapper to generate NHibernate code to access data objects. This is a semi-automated process.

  1. Download Puzzle Framework from http://www.puzzleframework.com/. Puzzle is a constantly evolving project so you might need to build ObjectMapper from source.
  2. Launch ObjectMapper and open the src/SnCore.omproj project.
  3. You must sync Data Source to Model, Tables to Classes and finally Model to Code. This produces the .cs and the .hbm.xml files in src/SnCore.Data.
  4. Until this is fixed in Puzzle there're a few replacements to be made in all .hbm.xml files. Thse enable lazy binding in NHibernate, fix ID naming and fix byte array types. I use a macro to do this after each synchronization with the data model. The source code for the macro is in src/SnCore.Data/PuzzleMacros.vb and can be run from Visual Studio.
  5. You should be able to successfully run all unit tests after a synchronization and rebuild. See Writing Unit Tests for more information.
© Vestris Inc., 2006-2007, All Rights Reserved | SnCore | Wed Mar 5 09:56:21 2008 | Doxygen 1.5.4