I have an object model like that:
Folder– simple structure with name etc.File– complex object containing reference toFolderin which it is contained.
Folder doesn’t know its Files and I don’t want it to know. The relation is many-to-one and should be known on File’s side only.
Anyway, I would like to rely on my database’s ON DELETE CASCADE feature, so that when I remove Folder, I want all Files within that Folder to be deleted automatically. I can’t use NHibernate’s cascading as there is no relation from Folder to File.
I know that there is on-delete="cascade" option for <key> element in case of one-to-many relationship, but I can’t find its equivalent for my model – when the relation is defined on many side.
Am I doing something wrong or do I really need to go through and delete all the Files within deleted Folder manually?
You could try to map the one-to-many side with
access="noop". That way you don’t need a property in your classes but still have the mapping.In Fluent NHibernate that would be someting like this:
Note: For that you need an
_filesfield of typeIEnumerable<File>in theFolderclass (limitation of Fluent NHibernate, can only map really existing fields or properties). But this field can always benull, it will never be used.