简体   繁体   中英

NHibernate.MappingException: No persister for

I'm begining my adventure with nHibernate and I have a problem.

My code: Model/Project.cs

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

Model/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();
}

And exception: No persister for: entity1.Model.Project

What is wrong?

I'm realy thank for everyone help. Sorry for my english. It's not too good.

Are you sure your assembly is called entity1.Model ? I think this is just the namespace and the assembly is entity1 right?

If you are not sure look into properties of your project.

And then change it within your web.config

<mapping assembly="entity1"/>

and mapping file

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

and you might be missing the call c.Configure() to load the xml config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM