I have a file attachment class (FileAttachment) which is used in several other classes.
e.g. An article contains multiple attachments. A category contains multiple attachments. These attachments are actually the same FileAttachment class but for obvious reason they are persisted in different tables. e.g. file attachment for an article in Article_FileAttachments table and category file attachments in a Category_FileAttachments table.
How can i represent this relationship in the nhibernate mappings? thx
Please see Chapter 8 for polymorphic mapping rules with NHibernate.
In short, you will need a discriminator column to specify what discriminator persists to what table. Here’s an instance from the NHibernate documentation, OR if you use inheritance, you will only need to map your derived classes as subclasses and specify the datatable name for each of them from within your base type class mapping.
You may observe that a Payment is a payment, whatever its type of payment. So, it is mapped as a IPayment. Then, subcategorized in multiple tables which represents each type of payment by its discriminator column.
Chapter 8 – Polymorphic mapping