错误:- The mapping for 'Model.GExam_DoctorAnswersEntity' was not added to the NHibernate configuration.
GExam_DoctorAnswers.hnm.xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">
  <class name ="GExam_DoctorAnswersEntity,Model" table="GExam_DoctorAnswersEntity">
    <id name="C_AnsId" column="C_AnswerID" type="Int32" unsaved-value="0">
      <generator class ="native"></generator>
    </id>
    <property name="CA_DoctorCode" column ="CA_DoctorCode" type="string" length="50" not-null="false"/>
    <property name ="CA_PaperCode" column="CA_PaperCode" type="string" length="50" not-null="false"/>
    <property name ="CA_QuestionCode" column="CA_QuestionCode" type="string" length="50" not-null="false"/>
    <property name ="CA_DoctorAnswer" column="CA_DoctorAnswer" type="string" length="50" not-null="false"/>
  </class>
</hibernate-mapping>
bin文件下的hibernate.cfg.xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory >
    <!--<property name="connection.provider">NHibernate.Test.DebugConnectionProvider, NHibernate.Test</property>-->
    <property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider, NHibernate</property>
    <property name="adonet.batch_size">10</property>
    <property name="show_sql">true</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=.;initial catalog=cmda_dremsShan;User Id=sa; Integrated Security=True;Pooling=False; Password=123456</property>
    <property name="query.substitutions">true 1, false 0, yes 1, no 0</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <!--<property name="use_outer_join">true</property>-->    
    <property name="command_timeout">10</property>
    <mapping assembly="Model"/>
  </session-factory>
</hibernate-configuration>
以上文件均设为嵌入的资源和始终复制,当调用  return _session.Get<GExam_DoctorAnswersEntity>(id);
会出现- The mapping for 'Model.GExam_DoctorAnswersEntity' was not added to the NHibernate configuration.错误

解决方案 »

  1.   

    是不是你的GExam_DoctorAnswersEntity这个类的映射文件的名称问题,按道理会去取相同名称的xml,但是你却没有 而是有GExam_DoctorAnswers.hnm.xml 导致发生错误"The mapping for 'Model.GExam_DoctorAnswersEntity' was not added to the NHibernate configuration".
      

  2.   

    try:GExam_DoctorAnswers.hbm.xml------>GExam_DoctorAnswersEntity.hbm.xml
      

  3.   

    按你说的我重新命名了一下,命名为GExam_DoctorAnswersEntity.xml,但是依然会出现那个问题
      

  4.   

    都检查下
    1、你的GExam_DoctorAnswersEntity的实体类的类名是这个吧?
    2、检查GExam_DoctorAnswersEntity是不是属于Model命名空间?
    3、检查GExam_DoctorAnswersEntity对应的是不是有个GExam_DoctorAnswersEntity.hbm.xml这个文件?
    4、查看GExam_DoctorAnswersEntity.hbm.xml里面的class的name ="GExam_DoctorAnswersEntity,Model"?
      

  5.   

    不是GExam_DoctorAnswersEntity.xml而是GExam_DoctorAnswersEntity.hbm.xml
      

  6.   

    出现了新的问题Could not compile the mapping document: Model.GExamXml.GExam_DocAnsStrEntity.hbm.xml怎么回事?
      

  7.   

    GExam_DocAnsStrEntity.hbm.xml你这里面的name是怎么写的?
    如:name ="GExam_DoctorAnswersEntity,Model"
    GExam_DoctorAnswersEntity:表示映射的类名
    Model:表示GExam_DoctorAnswersEntity的命名空间
    你查看一下GExam_DocAnsStrEntity这个类以及hbm.xml里面是否映射正确(类名和命名空间)
      

  8.   

      <class name ="GExam_DoctorAnswersEntity,Model" table="GExam_DoctorAnswersEntity">
    命名空间是Model,类名是DoctorAnswersEntity
    对应的GExam_DoctorAnswersEntity.hbm.xml文件
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">
      <class name ="GExam_DoctorAnswersEntity,Model" table="GExam_DoctorAnswersEntity">
        <id name="C_AnsId" column="C_AnswerID" type="Int32" unsaved-value="0">
          <generator class ="native"></generator>
        </id>
        <property name="CA_DoctorCode" column ="CA_DoctorCode" type="string" length="50" not-null="false"/>
        <property name ="CA_PaperCode" column="CA_PaperCode" type="string" length="50" not-null="false"/>
        <property name ="CA_QuestionCode" column="CA_QuestionCode" type="string" length="50" not-null="false"/>
        <property name ="CA_DoctorAnswer" column="CA_DoctorAnswer" type="string" length="50" not-null="false"/>
      </class>
    </hibernate-mapping>
    但是依然会出现:The mapping for 'Model.GExam_DoctorAnswersEntity' was not added to the NHibernate configuration
      

  9.   

    看急成啥了,类名是GExam_DoctorAnswersEntity
      

  10.   

    话说,我吧xml文件和实体类放在了同一个文件夹,把hibernate.cfg.xml放在了ui层的bin文件夹下,弱弱问一句,这路径这样对吗
      

  11.   


    name ="GExam_DoctorAnswersEntity,Model"
    GExam_DoctorAnswersEntity:表示映射的类名
    Model:表示GExam_DoctorAnswersEntity的命名空间
    但是你说命名空间是Model,类名是DoctorAnswersEntity  
    那么你感觉取到吗?
      

  12.   

    可以 我的也是这样的xml和实体类会编译成DLL 而hibernate.cfg.xml会输出到UI层的Bin文件夹下的.
      

  13.   

    亲,写错了,类名是GExam_DoctorAnswersEntity,映射的类也是GExam_DoctorAnswersEntity
      

  14.   

    哦哦哦好[email protected],先谢谢
      

  15.   

    哦哦哦好[email protected],先谢谢 
      

  16.   

    已发你邮箱这个例子 测试采用的是单元测试工具 NUnit 没有安装的话 那么请下载 http://www.nunit.org/index.php?p=download安装后打开NUnit  点击File --Open Project 然后选择NHibernateLibary\NHibernate.Test\bin\Debug下面的NHibernate.Test.dll
    会出现所有的测试方法 你可以单击方法右键点击Run 右边即可查看运行结果。