I am trying to use NHibernate to map an ASP.NET dropdownlist to a tabel in a SQL Server 2005 database. The table (SiteCANS) where i want to insert data has a foreign key relationship with another table in the database (Members). I think my problem is mapping this relationship using NHibernate. My mapping file code is as follows:
SiteCANS:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="WiscNet.Database.Model.SiteCANS, WiscNet.Database.Model" table="SiteCANS"
proxy="WiscNet.Database.Model.SiteCANS, WiscNet.Database.Model">
<id name="SiteCode" column="SiteCode" type="String">
<generator class="identity" />
</id>
<property name="CAN" column="CAN" type="String" length="50" not-null="false" />
<many-to-one
name="Member"
class="WiscNet.Database.Model.Member, WiscNet.Database.Model"
column="SiteCode" />
</class>
</hibernate-mapping>
Members
Code:
<bag name="SiteCANS" table="SiteCANS" order-by="SiteCode">
<key column="SiteCode" />
<one-to-many class="WiscNet.Database.Model.SiteCANS, WiscNet.Database.Model"/>
</bag>
</class>
When I use the above, I get a "Specified cast is not valid error". Anyone know why?