NHibernate: Same class for multiple tables -
I have a file attachment class (file attachment) which is used in many other classes.
For example, there are many attachments in one article. One category contains multiple enclosures. These attachments are actually the same file attachment class, but there are clear reasons that they are persisted in different tables such as the article_FileAttachments table The file attachment for the article and Category file attachment in the Category_File Attachment table.
How can I represent this relationship in nhibernate mapping? Thx
Please refer to chapter 8 for multiprogramming mapping rules with NHibernate.
In short, you will need a differentiation column to specify which table is different to that, here is an example from the NHibernate documentation, or if you use legacy You will only need to map your derivative classes in the form of subclasses and with their base type class mapping, you must specify the datatable name for each of them.
& lt; Class name = "IPayment" table = "payment" & gt; & Lt; Id name = "id" type = "int64" column = "PAYMENT_ID" & gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Asset name = "zodiac" column = "AMOUNT" /> ... & lt; Included-sub-class name = "credit card payment" table = "CREDIT_PAYMENT" & gt; & Lt; Major column = "PAYMENT_ID" /> ... & lt; / Joy-Subclass & gt; & Lt; Included-sub-class name = "cash payment" table = "CASH_PAYMENT" & gt; & Lt; Major column = "PAYMENT_ID" /> ... & lt; / Joy-Subclass & gt; & Lt; Included-sub-class name = "check payment" table = "CHEQUE_PAYMENT" & gt; & Lt; Major column = "PAYMENT_ID" /> ... & lt; / Joy-Subclass & gt; & Lt; / Square & gt;
You can see that payment is a payment, regardless of its payment type, it has been mapped as an IPMant. After this, it is sub-classified into several tables which present each type of payment through its discriminatory column.
Comments
Post a Comment