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  
  1.     {  
  2.         static void Main(string[] args)  
  3.         {  
  4.   
  5.             Test();  
  6.             
  7.   
  8.         }  
  9.         static void Test()  
  10.         {  
  11.             NHibernateHelper db = new NHibernateHelper();  
  12.             ISession session=  db.GetSession();  
  13.             using (var trans = session.BeginTransaction())  
  14.             {  
  15.                 User user = new User();  
  16.                 user.Age = 123;  
  17.                 user.Name = "janekim";  
  18.                 session.Save(user);  
  19.                 trans.Commit();  
  20.   
  21.             }  
  22.         }  


//NHibernateHelper帮助类

namespace ConsoleApplication2  
  1. {  
  2.     public class NHibernateHelper  
  3.     {  
  4.         private ISessionFactory sessfFactory;  
  5.   
  6.         public NHibernateHelper()  
  7.         {  
  8.             sessfFactory = GetSessionFactory();  
  9.   
  10.         }  
  11.   
  12.         private ISessionFactory GetSessionFactory()  
  13.         {  
  14.             Configuration config = new Configuration().AddAssembly(Assembly.GetExecutingAssembly());  
  15.             return config.BuildSessionFactory();  
  16.   
  17.         }  
  18.   
  19.         public ISession GetSession()  
  20.         {  
  21.             return sessfFactory.OpenSession();  
  22.         }  
  23.   
  24.    
  25.   
  26.     }  
  27. }  


//这里是User.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>  
  1. <nhibernate xmlns="urn:nhibernate-mapping-2.2">  
  2.   
  3.   <class name="ConsoleApplication2.Domain.User,ConsoleApplication2" table="User"></class>  
  4.     
  5.   <id name="Id" length="4">  
  6.     <generator class="vative"></generator>  
  7.   </id>  
  8.     
  9.   <property name="Name">  
  10.     <column name="Name" sqltype="nvarchar" length="50" not-null="true"></column>  
  11.   </property>  
  12.     
  13.   <property name="Age">  
  14.     <column name="Age" sqltype="int" length="4" not-null="true"></column>  
  15.   </property>  
  16.   
  17. </nhibernate>  

//App.config配置文件

<?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>


 

你可能感兴趣的:(validation)