关联引用未映射的类异常

Dmi*_*sky 3 .net nhibernate

我正在尝试使用NHibernate映射Northwind Employee实体:

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; }
}
Run Code Online (Sandbox Code Playgroud)

制图:

<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>
Run Code Online (Sandbox Code Playgroud)

我一直得到"关联引用unmapped类:NHibernateTests.Data.Employee"MappingException.它可以很好地与自我关联部分(Subordinates和ReportsTo)注释掉.

我的映射有什么问题?

小智 8

有时,当我们没有为特定HBM文件设置属性时会发生上述错误.因此,转到您的hbm文件属性并选择

BuildAction = EmbeddedResource
Run Code Online (Sandbox Code Playgroud)

我用Nhibernate环境测试了这个场景,wpf.


Dmi*_*sky 5

愚蠢的错误:使用了entity-name而不是table属性.