关于 Nhinernate 的one to one(转载)
时间:2011-05-11 来源:整天流浪的猫
public class Document {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual DocumentFile DocumentFile { get; set; }
}
public class DocumentFile {
public virtual int Id { get; set; }
public virtual Document Document { get; set; }
public virtual byte[] Data { get; set; }
}
//配置文件。
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateDocumentTest.Document, NHibernateDocumentTest" table="Documents" lazy="false">
<id name="Id" column="Id" type="integer">
<generator class="native" />
</id>
<property name="Name" column="Name" type="string" />
<many-to-one name="DocumentFile" cascade="all-delete-orphan"
lazy="proxy" column="DocumentFileId" unique="true" />
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateDocumentTest.DocumentFile, NHibernateDocumentTest" table="DocumentFiles" lazy="true">
<id name="Id" column="Id" type="integer">
<generator class="native" />
</id>
<property name="Data" column="Data" type="Byte[]" />
<one-to-one name="Document" constrained="true" property-ref="DocumentFile" />
</class>
</hibernate-mapping>
//终于搞定。
相关阅读 更多 +