错误:- 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_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的实体类的类名是这个吧?
2、检查GExam_DoctorAnswersEntity是不是属于Model命名空间?
3、检查GExam_DoctorAnswersEntity对应的是不是有个GExam_DoctorAnswersEntity.hbm.xml这个文件?
4、查看GExam_DoctorAnswersEntity.hbm.xml里面的class的name ="GExam_DoctorAnswersEntity,Model"?
如:name ="GExam_DoctorAnswersEntity,Model"
GExam_DoctorAnswersEntity:表示映射的类名
Model:表示GExam_DoctorAnswersEntity的命名空间
你查看一下GExam_DocAnsStrEntity这个类以及hbm.xml里面是否映射正确(类名和命名空间)
命名空间是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
name ="GExam_DoctorAnswersEntity,Model"
GExam_DoctorAnswersEntity:表示映射的类名
Model:表示GExam_DoctorAnswersEntity的命名空间
但是你说命名空间是Model,类名是DoctorAnswersEntity
那么你感觉取到吗?
会出现所有的测试方法 你可以单击方法右键点击Run 右边即可查看运行结果。