2010-01-27 90 views
3

我試圖到Northwind僱員實體與NHibernate映射:協會引用未映射類除外

public class Employee 
{ 
    public virtual int ObjectID { get; set; } 
    public virtual string LastName { get; set; } 
    public virtual string FirstName { get; set; } 
    public virtual string Title { get; set; } 
    public virtual string TitleOfCourtesy { get; set; } 
    public virtual DateTime HireDate { get; set; } 
    public virtual DateTime BirthDate { get; set; } 
    public virtual string Address { get; set; } 
    public virtual string City { get; set; } 
    public virtual string Region { get; set; } 
    public virtual string PostalCode { get; set; } 
    public virtual string Country { get; set; } 
    public virtual string HomePhone { get; set; } 
    public virtual string Extension { get; set; } 
    public virtual byte[] Photo { get; set; } 
    public virtual string Notes { get; set; } 
    public virtual string PhotoPath { get; set; } 

    public virtual ISet<Employee> Subordinates { get; set; } 
    public virtual Employee ReportsTo { get; set; } 
} 

映射:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
auto-import="true" namespace="NHibernateTests.Data" assembly="NHibernateTests"> 
    <class name="Employee" lazy="false" entity-name="Employees"> 
    <id name="ObjectID" access="property" column="EmployeeID" > 
     <generator class="native" /> 
    </id> 
    <property name="LastName" access="property" column="LastName"/> 
    <property name="FirstName" access="property" column="FirstName"/> 
    <property name="Title" access="property" column="Title"/> 
    <property name="TitleOfCourtesy" access="property" column="TitleOfCourtesy"/> 
    <property name="BirthDate" access="property" column="BirthDate"/> 
    <property name="HireDate" access="property" column="HireDate"/> 
    <property name="Address" access="property" column="Address"/> 
    <property name="City" access="property" column="City"/> 
    <property name="Region" access="property" column="Region"/> 
    <property name="PostalCode" access="property" column="PostalCode"/> 
    <property name="Country" access="property" column="Country"/> 
    <property name="HomePhone" access="property" column="HomePhone"/> 
    <property name="Extension" access="property" column="Extension"/> 
    <property name="Photo" access="property" column="Photo"/> 
    <property name="Notes" access="property" column="Country"/> 
    <property name="PhotoPath" access="property" column="PhotoPath"/> 

    <set name="Subordinates" table="Employees" access="property" lazy="false" inverse="true"> 
     <key column="ReportsTo"/> 
     <one-to-many class="Employee" /> 
    </set> 

    <many-to-one name="ReportsTo" column="ReportsTo" access="property" not-null="false"/> 
    </class> 
</hibernate-mapping> 

我不斷收到「協會引用未映射類:NHibernateTests.Data。 Employee「MappingException。 它可以很好地處理自我關聯的部分(下屬和ReportsTo)註釋掉。

我的映射有什麼問題?

回答

5

愚蠢的錯誤:使用實體名稱而不是屬性。

8

有時,上述錯誤發生在我們沒有爲特定HBM文件設置屬性時。 所以,去你hbm文件屬性,選擇

BuildAction = EmbeddedResource 

我已經測試過這種情況,與NHibernate環境WPF。

0

我得到這個相同的錯誤,導致大量的頭部劃傷。所以我只是想添加我的解決方案,以防其他人有相同的問題...

我在關係中引用的實體是abstract,這是愚蠢的複製/粘貼錯字的結果。一旦我拿出abstract出來,它執行得很好。