日期:2014-05-17  浏览次数:20413 次

NHibernate 用法
错误:- 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.错误



------解决方案--------------------
是不是你的GExam_DoctorAnswersEntity这个类的映射文件的名称问题,按道理会去取相同名称的xml,但是你却没有 而是有GExam_DoctorAnswers.hnm.xml 导致发生错误"The mapping for 'Model.GExam_DoctorAnswersEntity'