I have a view joining 3 tables together in a chain that i need to replace with a NHibernate mapping without any changes to the database. Is this possible?
This is a simplified example of my view:
SELECT tblTable1.*,tblTable2.*,tblTable3.MyProperty FROM tblTable1
OUTER JOIN
tblTable2 ON tblTable1.Table1Key = tblTable2.Table1Key
OUTER JOIN
tblTable3 ON tblTable2.Table2Key = tblTable3.Table2Key
so basicaly we select tblTable1 and join tblTable2 this works for me in NHibernate. My problem is tblTable3. How do i join it on a property from the joined table tblTable2?
When i do the mapping like this i get a query trying to join tblTable3 on Table1Key for some reason.
<class name="MyClass" table="tblTable1">
<id name="Table1Key">
<generator class="identity"/>
</id>
<property name="..." />
<join table="tblTable2">
<key column="Table1Key" />
<property name="..." />
</join>
<join table="tblTable3">
<key column="Table2Key???" />
<property name="..." />
</join>
</class>
in NH you can’t join in a join. the only way is to make it a reference, which does basicly the same thing
Edit Option 2: if you dont want
MyClass2Maybe you can tweak this: