2014-01-05 84 views
0

我開始與nHibernate的冒險,我有一個問題。NHibernate.MappingException:沒有persister

我的代碼: 型號/ Project.cs

namespace entity1.Model 
{ 
    public class Project 
    { 
     public Guid Id { get; set; } 
     public string Name { get; set; } 
     public string Description { get; set; } 
    } 
} 

型號/ Project.hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" namespace="entity1.Model" assembly="entity1.Model"> 
    <class name="entity1.Model.Project, entity1.Model" lazy="false"> 
    <id name="id" column="prj_id"></id> 
    <property name="Name" column="prj_name" /> 
    <property name="Description" column="prj_description" /> 
    </class> 
</hibernate-mapping> 

的Web.config

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory> 
     <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
     <property name="connection.connection_string">Server=(local);initial catalog=todo;Integrated Security=True</property> 
     <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> 
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
     <mapping assembly="entity1.Model"/> 
    </session-factory> 
    </hibernate-configuration> 

Test.aspx.cs

Project project = new Project(); 
// [...] 
Configuration c = new Configuration(); 
c.AddAssembly(Assembly.GetCallingAssembly()); 

ISessionFactory factory = c.BuildSessionFactory(); 
using (ISession session = factory.OpenSession()) { 
    using(ITransaction transaction = session.BeginTransaction()){ 
     session.Save(project); 
     transaction.Commit(); 
} 

和異常: 沒有留存爲:entity1.Model.Project

有什麼不對?

我真的很感謝大家的幫助。 對不起,我的英語。這不太好。

回答

1

您確定您的程序集叫做entity1.Model? 我認爲這只是命名空間,程序集是entity1對不對?

如果您不確定查看項目的屬性。

然後你的web.config

<mapping assembly="entity1"/> 

和映射文件

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" namespace="entity1.Model" assembly="entity1"> 

內改變它,你可能會丟失呼叫c.Configure()加載XML配置。

+0

我檢查了項目屬性中的程序集。有彙編:entity1。主命名空間:entity1。 接下來我在映射文件和web.config中爲命名空間=「entity1.Model」和程序集=「entity1」設置了命名空間和程序集。 不幸的是它也是錯誤的。 – kalinowski

+0

,你可能會錯過調用'configuration.Configure()' – MichaC

+0

是的!是它!真的感謝! – kalinowski

相關問題