代码之家  ›  专栏  ›  技术社区  ›  Dmitry Ornatsky

关联引用未映射类异常

  •  3
  • Dmitry Ornatsky  · 技术社区  · 16 年前

    我正在尝试将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>
    

    我一直在获取“关联引用未映射类:nhibernatests.data.employee”mappingException。 它可以很好地与自我联想部分(下属和报告)评论掉。

    我的地图怎么了?

    3 回复  |  直到 14 年前
        1
  •  8
  •   eeerahul Stalin Pimentel    14 年前

    有时,当我们不为特定的 HBM 文件。 所以,去你的 hbm 文件属性并选择

    BuildAction = EmbeddedResource
    

    我已经测试了这个场景,wpf和nhibernate环境。

        2
  •  5
  •   Dmitry Ornatsky    16 年前

    愚蠢错误:已使用 实体名 而不是 桌子 属性。

        3
  •  0
  •   DavGarcia    14 年前

    我也犯了同样的错误,导致了很多头疼。所以我只想添加我的解决方案,以防其他人有同样的问题…

    我在关系中引用的实体是 abstract 一个愚蠢的复制/粘贴错误的结果。一旦我采取 摘要 结果执行得很好。