Hello Frnds,
My Product table have one foreign key CategoryId . I don't know how to Map this table & how to insert CategoryId into Product Table. I am Posting my Code but It gives me runtime error.
Products.hbm.xml file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test_NHibernate_Join_Tables" assembly="Test_NHibernate_Join_Tables"
>
<class name="Test_NHibernate_Join_Tables.Products" table="tblProducts">
<id name="ProductId" type="int">
<generator class="native"/>
</id>
<property type="string" name="ProductName" >
<column name="ProductName"></column>
</property>
<set name="Category" inverse="true" cascade="all" >
<key column="CategoryId" />
<one-to-many class="Test_NHibernate_Join_Tables.Products"/>
</set>
</class>
</hibernate-mapping>
Product.cs File
Code:
public class Products
{
public virtual int? ProductId { get; set; }
Category _category;
public virtual Category Category
{
get
{
return _category;
}
set
{
_category = value;
}
}
public virtual string ProductName { get; set; }
}
Error Getting
Unable to cast object of type 'Test_NHibernate_Join_Tables.Category' to type 'Iesi.Collections.ISet'.