3
我有這些遺留表,我通過nhibernate訪問,基本的一個實體訪問是好的,但我真的需要得到連接工作。nhibernate映射,加入沒有主鍵和外鍵
理想情況下,我會有主鍵和外鍵來定義連接,但因爲這些是遺留表,我只有合併id是表的索引,這些索引已用於性能的原因,所以我不能改變。
反正我有JobHeader表和屬性表
JobHeader映射看起來像這樣的時刻:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="JobHeader " dynamic-update="true" table="JOB_HEADER">
<composite-id>
<key-property name="Company" column="JBH_COMPANY" type="String(6)" />
<key-property name="ContractRef" column="JBH_CONTRACT_REF" type="String(10)" />
<key-property name="JobRef" column="JBH_JOB_REF" type="String(10)" />
<key-property name="Status" column="JBH_STATUS" type="String(10)" />
</composite-id>
<property name="RowId" column="TK_ROWID" type="Int32" not-null="true" />
<property name="PropRef" column="JBH_PROP_REF" type="String(20)" not-null="false" />
</class>
</hibernate-mapping>
而且房產測繪是這樣的:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Property" dynamic-update="true" table="PROPERTY">
<composite-id>
<key-property name="Company" column="PRP_COMPANY" type="String(6)" />
<key-property name="Reference" column="PRP_REFERENCE" type="String(20)" />
</composite-id>
<property name="RowId" column="TK_ROWID" type="Int32" not-null="true" />
<property name="Name" column="PRP_NAME" type="String(40)" not-null="false" />
</class>
</hibernate-mapping>
在Jobheader它使用「PropRef」來保存「參考」屬性。
我想創建一個將被稱爲JobHeaderJoinedProperty 所以或許會是這個樣子了新的映射文件:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="JobHeaderJoinProperty" dynamic-update="true" table="JOB_HEADER">
<composite-id>
<key-property name="Company" column="JBH_COMPANY" type="String(6)" />
<key-property name="ContractRef" column="JBH_CONTRACT_REF" type="String(10)" />
<key-property name="JobRef" column="JBH_JOB_REF" type="String(10)" />
<key-property name="Status" column="JBH_STATUS" type="String(10)" />
</composite-id>
<property name="RowId" column="TK_ROWID" type="Int32" not-null="true" />
<property name="PropRef" column="JBH_PROP_REF" type="String(20)" not-null="false" /> </class>
<bag name="Property" fetch="join" >
<key column="Reference" property-ref="PropRef" />
<one-to-one class="Property"/>
</bag>
</class>
</hibernate-mapping>
然後希望那麼我JobHeaderJoinedProperty實體將能夠與訪問屬性實體它在這裏:
public virtual Property Property
{
get
{
return this.property;
}
set
{
this.property = value;
}
}
通過nhibernate連接兩個遺留表不應該太棘手?
我真的只是想複製內部連接在SQL會是這樣:
Select * from job_header inner join property on property.reference = job_header.propref