Solved: ClassMap when configuration in code, ClassMapping when configuration in config file, but mapping in code.
When trying to save an object of type Object1 to my database I get the error:
No persister for: Object1.
Class definition:
public class Object1
{
public virtual Guid Id { get; protected set; }
public virtual DateTime Created { get; protected set; }
public virtual DateTime LastModified { get; protected set; }
public virtual Other Reference { get; set; }
}
mapping:
public class Object1Mapping : ClassMapping<Object1>
{
public Object1Mapping()
{
Id(p => p.Id);
Property(p => p.Created);
Property(p => p.LastModified);
ManyToOne(p => p.Reference, m => m.Cascade(Cascade.Remove));
}
}
Configuration code:
sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012
.ConnectionString(c => c
.Server("serverUrl")
.Database("myMsSqlDatabase")
.Username("sa")
.Password("pasword1")))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<Object1Mapping>()
.AddFromAssemblyOf<Object1>()
.BuildSessionFactory();
All my classes are public and I added an AddFromAssemblyOf
for every class that needs a persister. Also I tried both adding the classes themselves and the mapping classes. I know that one AddFromAssembly
should be enough as should add all mapping classes from that assembly and all my mapping classes are in one project in one folder.
I managed to run diagnostics and it's looking through the correct Assembly, but it discovered no mappings, here is the result:
Fluent Mappings
Sources scanned:
Project.DomainModel.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Mappings discovered:
None found
Conventions
Sources scanned:
None found
Automapping
Skipped types:
None found
Candidate types:
None found
I've read tons of documentation and questions, it seems I'm missing something really obvious :(