Reputation: 13
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.
Upvotes: 1
Views: 16022
Reputation: 13410
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.
Upvotes: 2