tenwit wrote:
To do that you need to use property-ref on the one-to-one. That's not in NHibernate. So change from using one-to-one to many-to-one unique="true" property-ref="FormID". You'll need to add a FormID property for that to work.
Hey,
Thanks for the quick reply. I have made some head way but still missing something.
I changed the menu.hbm.xml to many-to-one and got some SQL that is closer.
The SQL now has the ProTracForm object where I was expecting the FormID. Here is the SQL that is generated.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.Menu,DTP" table="Menu">
<id name="Id" column="ItemID" type="Int64" >
<generator class="native"/>
</id>
<many-to-one name="MenuGroup" column="MenuGroupID" class="DTP.Data.MenuGroup,DTP" />
<property column="Description" name="Description" not-null="true" length="50" />
<property column="SortOrder" name="SortOrder" />
<property column="Type" name="Type" not-null="true" length="50" />
<property column="ItemName" name="ItemName" length="50" />
<many-to-one name="ProTracForm" unique="true" class="DTP.Data.ProTracForm,DTP" />
</class>
</hibernate-mapping>
Code:
NHibernate: SELECT this.ItemID as ItemID2_, this.Type as Type2_, this.SortOrder as SortOrder2_, this.MenuGroupID as MenuGrou2_2_, this.Description as Descript3_2_, this.ItemName as ItemName2_, this.ProTracForm as ProTracF7_2_, menugroup1_.MenuGroupID as MenuGrou1_0_, menugroup1_.Description as Descript2_0_, protracfor2_.FormID as FormID1_, protracfor2_.FormName as FormName1_, protracfor2_.Category as Category1_ FROM ProTrac.dbo.Menu this left outer join ProTrac.dbo.MenuGroup menugroup1_ on this.MenuGroupID=menugroup1_.MenuGroupID left outer join ProTrac.dbo.Form protracfor2_ on [b]this.ProTracForm=protracfor2_.FormID[/b] WHERE this.MenuGroupID = @p0
@p0 = '1'
You said to put in property-ref="FormID" but I am not sure about doing that. Do you mean to add a FormID to my Menu object along side the ProTracForm? That would give me this XML
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.Menu,DTP" table="Menu">
<id name="Id" column="ItemID" type="Int64" >
<generator class="native"/>
</id>
<many-to-one name="MenuGroup" column="MenuGroupID" class="DTP.Data.MenuGroup,DTP" />
<property column="Description" name="Description" not-null="true" length="50" />
<property column="SortOrder" name="SortOrder" />
<property column="Type" name="Type" not-null="true" length="50" />
<property column="ItemName" name="ItemName" length="50" />
<many-to-one name="ProTracForm" unique="true" property-ref="FormID" class="DTP.Data.ProTracForm,DTP" />
</class>
</hibernate-mapping>
then it says I don't have a FormID in the ProTracForm, so I used my primary key that is already there "Id" and it can not find that.
Reading the docs, I thought the property-ref was for when you have a FK that is not the PK of that foriegn object.
Thanks for the help.