HNibernate报错了 XML validation error: 未声明“urn:nhibernate-mapping-2.2:nhibernate”元素。

前端之家收集整理的这篇文章主要介绍了HNibernate报错了 XML validation error: 未声明“urn:nhibernate-mapping-2.2:nhibernate”元素。前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

请大神帮忙解决这个问题,这个HNibernate刚学,谢谢先。

出现这个错误:ConsoleApplication2.Mapping.User.hbm.xml(2,2): XML validation error: 未声明“urn:nhibernate-mapping-2.2:nhibernate”元素。

//这里是控制台

class Program
    {
        static void Main(string[] args)
        {

            Test();
          

        }
        static void Test()
        {
            NHibernateHelper db = new NHibernateHelper();
            ISession session=  db.GetSession();
            using (var trans = session.BeginTransaction())
            {
                User user = new User();
                user.Age = 123;
                user.Name = "janekim";
                session.Save(user);
                trans.Commit();

            }
        }


//NHibernateHelper帮助类

namespace ConsoleApplication2
{
    public class NHibernateHelper
    {
        private ISessionFactory sessfFactory;

        public NHibernateHelper()
        {
            sessfFactory = GetSessionFactory();

        }

        private ISessionFactory GetSessionFactory()
        {
            Configuration config = new Configuration().AddAssembly(Assembly.GetExecutingAssembly());
            return config.BuildSessionFactory();

        }

        public ISession GetSession()
        {
            return sessfFactory.OpenSession();
        }

 

    }
}



//这里是User.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<nhibernate xmlns="urn:nhibernate-mapping-2.2">

  <class name="ConsoleApplication2.Domain.User,ConsoleApplication2" table="User"></class>
  
  <id name="Id" length="4">
    <generator class="vative"></generator>
  </id>
  
  <property name="Name">
    <column name="Name" sqltype="nvarchar" length="50" not-null="true"></column>
  </property>
  
  <property name="Age">
    <column name="Age" sqltype="int" length="4" not-null="true"></column>
  </property>

</nhibernate>


//App.config配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate"/>
    </configSections>
  
    <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
      <property name="connection.driver_class">NHibernate.Driver.sqlClientDriver</property>
      <property name="connection.connection_string">
        Server=.;initial catalog=NHibernateSample;Integrated Security=SSPI
      </property>
      <property name="dialect">NHibernate.Dialect.Mssql2012Dialect</property>
    </session-factory>
  </hibernate-configuration>
  
  
</configuration>
希望能够帮我解决,thank you!!!

猜你在找的XML相关文章