Hi.
I found many articles around the net and even saw a post here about this issue but still i keep on getting the exception:
NHibernate.MappingException : An association from the table ItemsCategories refers to an unmapped class: Entities.CategoryHere are my files (Each class resides in a separate file, but in same namespace):
Code:
namespace DOM.Entities
{
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
.... etc.
public IList<Category> Categories { get; set; } // This is the new addition
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Item> Items; { get; set; }
}
Here are the mappings:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DOM"
namespace="DOM.Entities">
<class name="Item" table="Items" lazy="true" abstract="false">
<id name="Id" column="ItemId" type="Int32">
<generator class="native"/>
</id>
<property name="Title" type="string"/>
<!-- ... etc. -->
<bag name="Categories" table="ItemCategories" cascade="all">
<key column="ItemId"/>
<many-to-many class="Category" column="CategoryId" />
</bag>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DOM"
namespace="DOM.Entities">
<class name="Category" table="Categories" lazy="true" >
<id name="Id" column="CategoryId" type="Int32">
<generator class="native"/>
</id>
<property name="Name" type="string"/>
<bag name="Items" table="ItemCategories" cascade="all">
<key column="CategoryId"/>
<many-to-many class="Item" column="ItemId" />
</bag>
</class>
</hibernate-mapping>
The Item class didn't have categories before, that's a new feature and it matches a many-to-many collection.
Can anybody please help with that exception?
Do I need to define a class ItemCategories that would map to that table? I'm pretty lost.....
Thanks ahead!
Zvika