我在我的數據庫中的這些相關的表:NHibernate的:如何正確模擬這種模式
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.
這就是他們目前在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>
我知道,這個映射呢不太適合附件表的模式。
有沒有更好的方法來映射這些表?
(這與my previous question。)
正如一個附註,而不是你的問題的實際答案,你的映射文件中的類型聲明不需要顯式聲明「System.String」,你可以簡單地放在「string」中。 – Jay 2009-12-09 01:27:12
你甚至不需要在大多數情況下指定類型。 NHibernate默認會使用屬性類型。有些情況下你想要,比如枚舉或者自定義類型。 – 2009-12-09 01:45:55
名稱/列相同。 NHibernate使用約定,即列名與屬性名稱相同,除非另有指定。 – 2009-12-09 01:47:09