NHibernates SchemaUpdate feature 2008-03-21

Ayende wrote about Setting Up Zero Friction Projects - Data Access, and mentioned the new SchemaUpdate feature in NHibernate.

The idea being that the ddl is automagically created from the nhibernate hbm.xml files, and executed against the delvelopers local database.

Something like:

  1. Developer A changes the Order.hbm.xml where he adds a new field Discount.
  2. In ApplicationStart the ddl alter script is generated and executed against Developer A's local database, the next time the developer starts the application.
  3. Developer eventually does a check-in of the Order.hbm.xml, along with the other changes.
  4. Developer B does a get latest.
  5. When he starts the application, ApplicationStart executes the change dll, and now Developer B's local database is up to speed.

At what cost? Well, almost zero :-)

I have created a sample C# VS2008 Solution, that can be downloaded here.


Anonymous said...

Would it be possible to post a Visual Studio 2005 solution? I can't open the solution with Visual Studio 2008 Express.


Morten Lyhr said...

I have updated the solution so that it has a VS 2005 solution file too.

Note that this is a web project, so you need SP1 for VS 2005.

Look at the web.config to change the database NHibernate uses.

kpatton said...

it doesn't track deletions to old fields, only additions so is not really usable in my opinion.

Sushi said...

I'm using Fluent NH for mapping and NH as ORM in my C# application..
The problem is with schemaupdate class.. if I create an instance of
that.. using the configuration I got from my exposeconfiguration
function.. It doesnot update the schema.. I need some better
documentation on SchemaUpdate class.. or might be.. setting the
configuration to accomodate the new schema in an old database.. for
versioning purposes..

I have tried a lot of variations but no DDL command is reflected on
the actual database using SchemaUpdate :(

is this my problem:


Thankx in advance.

Sushant Khurana

ThienThai said...

i using NHibernate with PostgresSQL
my database has many schema it is created automatic every month so each month a Schema Ex: myschema.Order, myschema0509.Order and so on. How can i create a query like this:
"Select ... from myschema.Order, myschema0509.Order" using HQL
Anyone help me