NHibernate on-delete = cascade with side relation

I have an object model:

  • Folder - a simple structure with a name, etc.
  • File- a complex object containing a link to Folderin which it is contained.

A folder does not know its files , and I do not want it to know. The relationship is ambiguous and should only be known on the file side.

In any case, I would like to use the ON DELETE CASCADE database function, so when deleting a folder, I want all the files in this folder to be deleted automatically. I cannot use NHibernate cascading because there is no relation between the folder and the file.

I know that there is an optionon-delete="cascade" for an element <key>in the case of a one-to-many relationship, t find its equivalent for my model - when the relationship is defined on the side of the side .

Am I doing something wrong or do I really need to go through and delete all the files in the remote folder manually?

+1
source share
1 answer

You can try to match the one-to-many side with access="noop". Thus, you do not need a property in your classes, but there is still a mapping.

In Fluent NHibernate, which will look like this:

HasMany(Reveal.Member<Folder, IEnumerable<File>>("_files"))
   .KeyColumn("column_name")
   .Access.NoOp()
   .Inverse()
   .ForeignKeyCascadeOnDelete();

. _files IEnumerable<File> Folder ( Fluent NHibernate, ). null, .

+1

All Articles