The mapping for 'Model.GExam_DoctorAnswersEntity' was not added to the NHibernate configuration
错误:- 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' 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"?
类名是GExam_DoctorAnswersEntity