I'm having a select n+1 problem with a one-to-one mapping. And conflicting advice leaves me without a solution.
My one-to-one assocation is mapped exactly as per advice given in
NHibernate In Action and the NHibernate documentation (see mapping files below).
But if I add the 'constrained=true' attribute to my one-to-one mapping, this error results:
Quote:
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'AccountID', table dbo.AccOther'; column does not allow nulls. INSERT fails.
I'm not yet quite sure what other parts of my current mapping (which works) I have to delete in order to get this new mapping concept to work.
My main 'Account' mapping:
Code:
<class name="Account" table="Accounts">
...
<one-to-one name="Other"
class="AccountOther"
property-ref="Account"
cascade="all" />
...
And my one-to-one AccountOther:
Code:
<class name="AccountOther" table="AccOther">
...
<many-to-one name="Account"
class="Account"
column="AccountID"
cascade="all"
unique="true" />
...