2014-01-05 36 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

相关问题