When I tried to perform CRUD operations on a POCO against a database, I got an exception: NHibernate Mapping Exception: No persister for: MyNamespace.Model.User.
Here is my code:
namespace MyNamespace.Model
{
public interface IModel<TID>
{
TID ID { get; set; }
}
public class User : IModel<int>
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
}
}
and here is my mapping
namespace MyNamespace.Model.Mapping
{
public class UserMap : ClassMap<User>
{
public UserMap()
{
Table("User");
Id(x => x.ID);
Map(x => x.Name)
.Length(255)
.Unique()
.Not.Nullable();
}
}
}
In my configuration file I have added the assembly mapping:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
...
<mapping assembly="MyNamespace" />
</session-factory>
</hibernate-configuration>
I know that such issue occurs if using hbm files, when not set as embedded resources. But in my case I am using Fluent NHibernate where no such files are used. I also read here, that the Mapping classes should be public - I have done that as you can see. All my properties of the model class are virtual (to allow proxies to do their magic). I am absolutely unaware of what I am missing here and I'd be glad to hear any suggestions for this issue.