SchemaUpdate for NHibernate - HACKED & DEFACED by bd0rk ::SOH-Crew::
Oxite Administrator (gravatar)

SchemaUpdate for NHibernate

I was looking into how SchemaExport and SchemaUpdate work for NHibernate.Tool.hbm2ddl. I'm about to put another website up and I wanted to be able to generate the database schema for the new site, instead of creating the tables by hand. I've done this for a couple applications before, but I have to admit to only vaguely understanding how hbm2ddl works. This is probably do to the almost total lack of documentation on these features, outside of a quick run-down in the nhibernate docs .

At first glance it looks like Export generates SQL create table statements, and SchemaUpdate generates a bunch of update statements. But one thing I was curious about was whether or not SchemaUpdate would create new tables if they didn't exist. After looking at the current nhibernate source code, it appears that SchemaUpdate iterates through each table and if the table exists in the destination database then it generates an update script, otherwise it generates a create script.

NHibernate.Cfg.Configuration generates both the update, drop, and create scripts. SchemaUpdate will connect to the database and check the database's metadata to see if the table exists.

I also looked into Fluent Nhibernate's BuildSchema, curious to see how they approached it. But it appears to be little more than a wrapper around SchemaExport.

Commenting is disabled for this post.