2012-07-19 52 views
0

的app.configNHibernate的MappingException,沒有留存爲:NHiberDeneme.Sinifi

<?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="dialect">NHibernate.Dialect.MsSql2008Dialect</property> 
     <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
     <property name="connection.connection_string">Data Source=localhost;Initial Catalog=hiberdb;Integrated Security=True;</property> 
     <property name="default_schema">hiberdb.dbo</property> 
     <mapping assembly="NHiberDeneme"/> 
    </session-factory> 
    </hibernate-configuration> 
</configuration> 

的Program.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using NHibernate.Cfg; 
using NHibernate; 

namespace NHiberDeneme 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 
      Configuration cfg = new Configuration(); 
      cfg.AddAssembly("NHibernate"); // projenin assembly Adi 
      ISessionFactory factory = cfg.BuildSessionFactory(); 
      ISession session = factory.OpenSession(); 
      ITransaction transaction = session.BeginTransaction(); 
      Sinifi sinif = new Sinifi(); 
      sinif.Id = 1; 
      sinif.SinifAdi = "sinif adi"; 
      session.Save(sinif); 
      session.Flush(); 
      session.Clear(); 
      transaction.Commit(); 
      session.Close(); 
     } 
    } 
} 

Sinifi.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using NHibernate.Mapping; 

namespace NHiberDeneme 
{ 
    class Sinifi 
    { 
     private int _id; 
     private string _sinifadi; 

     public int Id 
     { 
      get { return _id; } 
      set { _id = value; } 
     } 

     public string SinifAdi 
     { 
      get { return _sinifadi; } 
      set { _sinifadi = value; } 
     } 
    } 
} 

Sinifi.hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"> 
    <class name="NHiberDeneme.Sinifi, NHiberDeneme.Program, NHiberDeneme" table="Sinifi" lazy="false"> 
    <id name="Id" column="Id" type="int"> 
     <generator class="assigned" /> 
    </id> 
    <property name="SinifAdi" column="SinifAdi" type="String" length="10"/> 


    <bag name="SinifiId" table="SinifiId" inverse="true"> 
     <key column="Id" /> 
     <one-to-one class="NHiberDeneme.Sinifi, NHiberDeneme.Program, NHiberDeneme" /> 
    </bag> 

    </class> 
</hibernate-mapping> 

我的SQL關係在這裏http://i.stack.imgur.com/jOT5M.jpg

給我 「MappingException,沒有留存爲:NHiberDeneme.Sinifi」 的錯誤。我嘗試了很多方法,我也嵌入了資源。

回答

0

有了這個錯誤NHibernate告訴你,你的類映射有什麼問題。 NHibernate無法找到類映射,或無法正確解析它。

通過查看它,映射文件中的類名似乎是錯誤的。

從NHibernate的文檔上class mapping

:持久化類的完全限定.NET類的名稱(或 接口),包括它的程序集名稱。

在你的代碼中,你有這個類名:NHiberDeneme.Sinifi, NHiberDeneme.Program, NHiberDeneme。這不是有效的.NET assembly qualified class name。如果你的程序集名稱爲NHiberDeneme,你應該有這樣的:

<class name="NHiberDeneme.Sinifi, NHiberDeneme" ... /> 

...如果裝配的名字是NHiberDeneme.Program映射應該是這樣的:

<class name="NHiberDeneme.Sinifi, NHiberDeneme.Program" ... /> 
相關問題