I have an object in my application, Item,> which has a one to one relationship to Result. The database tables are as follows:
TABLE Item
ItemId INT NOT NULL (PK)
ResultId INT NULL (Foreign key to Result)
TABLE Result
ResultId INT NOT NULL (PK)
ResultColumns etc ...
In my mappings I have this as:
<class name="Item" table="Item">
.....
<many-to-one name="Result" column="ResultId" cascade="all"/>
</class>
<class name="Result" table="Result">
....
<one-to-one name="Item" class="Item"/>
</class>
I recently started to write a query where I wanted to ensure the Result was returned when querying Items and I used the "fetch join" in my query to do this. This worked in that the SQL joined the two tables and returned all the necessary data but then for each result row another query would be executed against the Result table.
I have read Ayende's post on this (http://ayende.com/Blog/archive/2009/04/19/nhibernate-mapping-ltone-to-onegt.aspx) and understand this but I think it should be possible to get this to work and only execute one query. The last question in comments of this article describes the same situation and the advice is to try the using constrained="true" which I have tried but does not seem to affect the queries produced.
Has anyone got this situation working?