Random Musings

June 13, 2009

nHibernate SchemaExport

Filed under: nhibernate — haditeo @ 3:02 pm

Today i spent some time to learn nHibernate for the first time. This article is really fabolous. Credit to Gabriel Schenker as the author.

When i followed the article, somehow i noticed that the ‘Category’ records that have been added to the database was wiped out. Very very strange indeed, i cannot find any exception araised, the nUnit tests are working properly.

My first investigation is to turn on the profiler and these results come up :

table is dropped

Please be aware that i have created the Category table in the database, so why this nHibernate drop my ‘Category’ table? That means somewhere inside the code, it re-creates the necessary table for me automatically.

Finally i found the culprit, after careful debugging and googling, this line is the culprit

public void SetupContext()
    new SchemaExport(_configuration).Execute(false, true, false, false);

The SchemaExport method automatically create the necessary tables for me based on the Domain that i have been created. This is cool ! I noticed that in the article, i didn’t even have to create a single table in the database. Fabolous

I have also found this article NHibernate:How to Build Great Mappings and use SchemaExport while googling for the SchemaExport method


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: