Restricting deletion with NHibernate

Posted by FrontSvin on Stack Overflow See other posts from Stack Overflow or by FrontSvin
Published on 2010-04-22T10:12:30Z Indexed on 2010/04/22 10:13 UTC
Read the original article Hit count: 169

I'm using NHibernate (fluent) to access an old third-party database with a bunch of tables, that are not related in any explicit way. That is a child tables does have parentID columns which contains the primary key of the parent table, but there are no foreign key relations ensuring these relations. Ideally I would like to add some foreign keys, but cannot touch the database schema.

My application works fine, but I would really like impose a referential integrity rule that would prohibit deletion of parent objects if they have children, e.i. something similar 'ON DELETE RESTRICT' but maintained by NHibernate.

Any ideas on how to approach this would be appreciated. Should I look into the OnDelete() method on the IInterceptor interface, or are there other ways to solve this?

Of course any solution will come with a performance penalty, but I can live with that.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about fluent-nhibernate