Okay, I have a database, but no tables in it. I have some entity classes. I'm trying to setup Fluent NH to do automappings with automatic schema export.
First, this is possible, right?
Second, if so, what am I doing wrong here:
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c.Is(@"Data Source=foo;Initial Catalog=bar;Integrated Security=True")))
.Mappings(m => m.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf<Employee>()
.Where(t => t.Namespace.Contains("Entities"))))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private void BuildSchema(Configuration cfg)
{
new SchemaExport(cfg).Create(false, true);
}
I am getting an error "Object reference not set to an instance of an object" on the ".Where" line above. If I take out the .Where condition, I get an error "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."
EDIT:
Some additional information: I changed the .Where statement to specifically outline which entities to include. I.e. ".Where(t => t.Name.Contains("Employee")", etc. When I did that, I got an error about a missing dependency (NHibernate.ByteCode.Castle). When I resolved that, it works fine. I still don't understand why this works though.