views:

296

answers:

2

I am writing an application with a hand-crafted domain model (classes) and a hand-crafted data model (tables/relationships), and letting NHibernate take care of the mapping.

Is it best to tell the database to perform cascading updates or deletes or to tell NHibernate to do it (cascade="all-delete-orphan")? Can they both be set up to do it at the same time?

+1  A: 

I prefer to let NHibernate do this for me. It's easier to setup and it works well.

cascade: all-delete-orphan is something that you wouldn't be able to do in SQL without a trigger, so there's another reason

Ben Scheirman
A: 

Can they both be set up to do it at the same time?

I think if you try, you might get NHibernate complaining, as most of it's operations check the row count to ensure that the expect number of rows were inserted/updated/deleted.

As Ben says, get NHibernate to do it.

Ultimately, NHibernate (and ORMs in general) let you think of the database as a storage and retrieval mechanism. You still want to create constraints, primary keys, foreign keys, and indexes, but the ORM should obey these rules anyway. As with any data-access scenerio, if you find yourself creating complex constraints in the database, then remember that these rules will have to be duplicated in your application.

David Kemp