2013-07-07 45 views
0

当我运行的应用程序,我得到“没有persister为Test.Student”错误 我是新的Nhibernate映射,我不知道这一点
我该如何解决? plz帮助没有persister的类错误

NHibernate的配置部分

的App.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<configSections> 
    <section name="hibernate-configuration" 
    type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> 
</configSections> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
<session-factory> 
    <property name="connection.provider"> 
    NHibernate.Connection.DriverConnectionProvider 
    </property> 
    <property name="connection.driver_class"> 
    NHibernate.Driver.SqlClientDriver 
    </property> 
    <property name="connection.connection_string"> 
    Server=(local);database=Student;Integrated Security=SSPI; 
    </property> 
    <property name="dialect"> 
    NHibernate.Dialect.MsSql2005Dialect 
    </property> 
    <!--<property name="proxyfactory.factory_class"> 
    NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernates 
    </property>--> 
    <property name="show_sql"> 
    false 
    </property> 
</session-factory> 

主程序

的Program.cs

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using NHibernate; 
    using NHibernate.Cfg; 
namespace Test 
    { 
    class Program 
    { 
     static void Main(string[] args) 
     {   
     ISessionFactory factor = new Configuration().Configure().BuildSessionFactory(); 
     if(factor!=null){ 
      Console.WriteLine("Configured"); 
     } 
     else{ 
      Console.WriteLine("Not Configured"); 
     } 
     Student std = new Student { Fname = "James", Lname = "Bond", Address = "32 Baker Street", Institution = "MIT" }; 
     using (ISession session = factor.OpenSession()) 
     { 
      using (ITransaction transaction= session.BeginTransaction()) 
      { 
       try 
       { 
       session.Save(std); 
       transaction.Commit(); 
       session.Close(); 

       } 
       catch(Exception e) 
       { 
        Console.WriteLine("ERROR :" + e); 
       } 
      }   
     }    
    } 
    //protected ISessionFactory factory; 


    protected void execute_query() 
    { 

    } 
} 

}

映射部分

Student.hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
     <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> 
     <class name="Test.Student" table="Info" lazy="true"> 
    <id name="Id" type="int" column="Id"> 
     <generator class="native" /> 
    </id> 

     <property name="Fname" column ="Fname"/> 
<property name="Lname" column="Lname"/> 
<property name="Address" column="Address"/> 
<property name="Institution" column="Institution"/> 

<!-- We don't have to specify a column name if its the same 
    as the variable name --> 

+1

您是否已将XML文件构建操作设置为“Embedded Resource”? –

+0

是的,我做了,但它没有任何区别 – Taskin

回答

1

描述here您需要add mapping assembly nameapp.config文件。

<property name="show_sql">false</property> 
    <mapping assembly="Test"/> <!-- Here --> 
</session-factory> 

还要确保如果没有XML文件标记为Embedded Resource

+1

谢谢:)真的有帮助 – Taskin

相关问题