I can’t figure out why Fluent NHibernate automapping and schema generation aren’t working.
I’ve this code:
return Fluently
.Configure()
.Database
(
MsSqlConfiguration.MsSql2005.ConnectionString
(
c => c.FromConnectionStringWithKey("dataAccess")
)
)
.Mappings(config => config.AutoMappings.Add(AutoMap.Assembly(ObjectsAssembly, new ORMAutoMappingConfiguration())))
.ExposeConfiguration(config => new SchemaExport(config).Create(true, true))
.BuildSessionFactory()
.OpenSession();
And:
public sealed class ORMAutoMappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return member.DeclaringType.IsSubclassOf(typeof(DomainObject));
}
}
The database and mappings aren’t created.
“ObjectsAssembly” is a one got in a property, I’ve watched it and I could determine that this is the right assembly and it has domain objects inheriting DomainObject.
Another thing is automapping configuration class is never required in the process, ShouldMap isn’t invoked by FNH.
What’s wrong?
Thank you.
Sadly, this was a very easy to solve problem! I was overriding ShouldMap(Member) instead of ShouldMap(Type) overload.
That’s any type was going to be mapped, which is wrong because not all of them were domain objects.
I’ve my domain model and database working!
Thank you anyway.