I have these related tables in my database:
table [Files]: FileID FileName ------ -------- 1 /data/foo.jpeg 2 /data/bar.gif table [Attachments]: FileID DocumentID Caption ------ ---------- ------- 1 10 Foo is awesome. 1 20 Foo is horrible. 2 10 Bars are my favorite. table [Documents]: DocumentID Title ---------- ----- 10 Things Jack loves. 20 Stuff Mary hates.
This is how they are currently mapped in NHibernate:
<class name="File" table="Files">
<id name="Id" type="System.Int32" column="FileID">
<generator class="identity" />
</id>
<property name="FileName" column="FileName" type="System.String" />
</class>
<joined-subclass name="Attachment" table="Attachments" extends="File">
<key column="FileID" />
<property name="DocumentID" column="DocumentID" type="System.Int32" />
<property name="Caption" column="Caption" type="System.String" />
</joined-subclass>
<class name="Document" table="Documents">
<id name="Id" type="System.Int32" column="DocumentID">
<generator class="identity" />
</id>
<property name="Title" column="Title" type="System.String" />
</class>
I know that this mapping does not quite fit the schema for the Attachments table.
Is there a better way to map these tables?
(This is related to my previous question.)