I have following project's structure:
My models are in NHibernateTesteWeb.Domain.Entity
and my maps are in NHibernateTesteWeb.Data.Map
Here is my Company class:
namespace NHibernateTesteWeb.Domain.Entity
{
public class Company
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
}
}
and here the map class for the Company:
namespace NHibernateTesteWeb.Data.Map
{
public class CompanyMap : ClassMap<Company>
{
public CompanyMap()
{
Table("Company");
Id(c => c.Id).GeneratedBy.Native();
Map(c => c.Name);
}
}
}
In NHibernateHelper class:
...
static NHibernateHelper()
{
_sessionFactory = Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2012.ConnectionString(c=>c.Server(@"(localdb)\Projects")
.Database("StockAnalyser")
.TrustedConnection()))
.Mappings(c => c.FluentMappings.AddFromAssemblyOf<Company>())
.Mappings(c => c.FluentMappings.AddFromAssemblyOf<BDICode>()).BuildSessionFactory();
}
When I run solution, it raises the following exception:
No persister for: NHibernateTesteWeb.Domain.Entity.Company
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
I was getting a same error with xml mapping. Then I change for the Fluent mapping. But the error wasn't solved.
I have hosted my project in github for most easily you help me: https://github.com/samsg/NHibernateSample
Thank you very much for your useful help.
I'm wondering if this is because you've chained the calls to Mappings()
. Can you try:
static NHibernateHelper()
{
_sessionFactory =
Fluently.Configure()
// ...
.Mappings(
c =>
c.FluentMappings
.AddFromAssemblyOf<Company>()
.AddFromAssemblyOf<BDICode>())
.BuildSessionFactory();
}
This is from: https://stackoverflow.com/a/6062220/1162077