Reputation: 842
I thought I knew my way around NHibernate, but I must be doing something stupid. I have a table/class called Category. When I pull data from my GetAll method, nothing returns, but there are no errors either.
The class is:
namespace Model
{
[Serializable]
public partial class Category
{
public virtual int Id { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual DateTime UpdatedOn { get; set; }
public virtual string Name { get; set; }
public override bool Equals(object oneObject)
{
return oneObject is Category && (this.GetHashCode() == ((Category)oneObject).GetHashCode());
}
public override int GetHashCode()
{
return Id.ToString().GetHashCode();
}
}
}
Mapping file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="Model" assembly="Model" xmlns="urn:nhibernate-mapping-2.2">
<class name="Category" lazy="true" table="`categories`"><!--test only!!-->
<id name="Id" access="property" column="`category_id`">
<generator class="native" />
</id>
<property name="Name" column="`name`" length="50" />
</class>
</hibernate-mapping>
If I add a many-to-one reference in another table, then it errors with: An association from the table manufacturer_categories refers to an unmapped class: Model.Category
.
It seems obvious to me that NHibernate is not recognizing my mapping file. What stupid thing am I missing?
Upvotes: 0
Views: 320
Reputation: 22424
Have you checked that your XML file is marked as an embedded resource?
Upvotes: 1
Reputation: 7284
Using full qualified name of the class, may solve the problem
<class name="Modle.Category" lazy="true" table="`categories`">
Also make sure that when configuring Nhibernate you have added the assembly containing Category mapping file
Configuration cfg = new Configuration();
cfg.Configure();
// Add class mappings to configuration object
Assembly mappingAssembly = AssemblyContatingTheCategoryMappingXMLFile;
cfg.AddAssembly(mappingAssembly);
Another hint will be setting the xml file as Embedded Resource
on properety tab
Upvotes: 2