In SQL Server 2008 R2 given a table structure of three (or more) one to one related tables, for example… (CaseId is the common primary key)
CaseTable:
CaseId
Col1
Col2
CaseDetailTable:
CaseId
Col1
Col2
CaseMoreDetailTable:
CaseId
Col1
Col2
Then put a view over the top of it e.g.
CREATE VIEW MyView
SELECT CaseTable.Col1 AS CaseCol1, CaseDetailTable.Col1 AS CaseDetailCol1,
CaseMoreDetailTable.Col1 AS CaseMoreDetailCol1
FROM CaseTable
INNER JOIN CaseDetailTable
ON CaseTable.CaseId = CaseDetailtable.CaseId
INNER JOIN CaseMoredetailTable
ON CaseTable.caseId = caseMoreDetail.CaseId
Now, if I map NHibernate to the view will it be able to lazy load through the view and not, for example select data from CaseMoreDetail if the view were called with…
SELECT CaseCol1, CaseDetailCol1
FROM MyView
Or, would it better to map the three tables to entities and thus ensure it can lazy load?
A one to one mapping does not supports lazy loading AFAIK. The same for the view, if you map the view you stick into the view all the join so there is no way to lazy load the associations. Try to specify the associated parts as
<many-to-one>association in the main entity.