FoodCandy!

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 2000
  • Puzzle Framework (ObjectMapper)

SQL Server

This is where everything starts. Think object oriented approach at a 100 percent. 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 99 percent of cases.

After you create new tables, export the database schema to src/SnCore.Data/SnCoreSqlServer.sql.

  1. Right click on the SnCore database in Enterprise Manager.
  2. Choose All Tasks, Generate SQL Script.
  3. Click Show All, select Script All Objects.
  4. In Formatting remove the generation of DROP commands to preserve data on upgrade.
  5. In Options, check all four Table Scripting Options.
  6. Choose the MS-DOS file format and Create one file.
  7. Confirm and save to SnCore.Data/SnCoreSqlServer.sql.

Puzzle Framework and ObjectMapper

ObjectMapper is heavily used to generate NHibernate code to access data objects.

  1. Download Puzzle Framework from http://www.puzzleframework.com/.
  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.
  5. You should be able to successfully run all unit tests after a synchronization and rebuild. See Unit Tests for more information.
© FoodCandy, 2006-2007, All Rights Reserved | FoodCandy | Sun Oct 7 10:48:50 2007 | Doxygen 1.4.6-NO