我以爲我知道我在NHibernate的方式,但我一定在做一些愚蠢的事情。我有一個名爲Category的表/類。當我從我的GetAll方法中提取數據時,沒有任何迴應,但也沒有錯誤。NHibernate沒有看到表格,MappingException
類是:
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();
}
}
}
映射文件:
<?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>
如果我添加一個多到一的另一個表中的參考,然後將其與錯誤:An association from the table manufacturer_categories refers to an unmapped class: Model.Category
。
在我看來很明顯NHibernate沒有識別我的映射文件。我錯過了什麼愚蠢的東西?
Didja檢查出明顯的事情,比如添加.hbm部分XML文件,或者確保它被設置爲嵌入的內容? – 2013-05-06 21:39:24
@Cosmo_D - 是的,我檢查了.hbm.xml。什麼是「嵌入式內容」? – scojomodena 2013-05-06 21:58:21
查看http://stackoverflow.com/questions/16340974/createsqlquery-works-but-queryover-doesnt-with-nhibernate/16377359#16377359嵌入式資源 – Rippo 2013-05-07 04:44:22