views:

670

answers:

1

Ok, NHibernate question here. I have two objects that I would like to map to each other. I have the "Vendor" and the "Township" ... now the two should be linked by zip code, NOT ID. I have done this many times btw objects using id's but never something like this.

The issue I am having it that the ZipCodes while stored as strings are somehow being turned into integers (leading zero being dropped)? Either that or it is using the ID from one of the objects.

Here is my error:

Server Error in '/HQWebsite' Application. No row with the given identifier exists[HQData.Objects.Township#7922]

It's also not the data in the database I looked there as well the data is accurate.

Here is how I mapped the Vendor xml file:

<many-to-one name="_Township" column="ZipCode" foreign-key="ZipCode" class="HQData.Objects.Township, HQData" />

Here is the property from the township one:

   <set name="_Vendors" cascade="all">
      <key  column="ZipCode" foreign-key="ZipCode"/>
      <one-to-many 
         class="HQData.Objects.Vendor, HQData"/>
    </set>

Is anyone familiar with NHibernate and has done this before? Thanks!

+2  A: 

This has been fixed! I needed the property-ref property in the Vendor .xml file for the many to one relationship.

Thanks!

Sara Chipps