Reputation: 26141
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.
Upvotes: 2
Views: 1350
Reputation: 2015
I believe that the NHibernate.ByteCode.Castle assembly is used to create proxy classes in NHibernate.
I'm guessing that when you tried to create the Schema, or Configuration, a reference to the proxy generator was required. That's why adding the reference allowed fixed your problem.
You can read a little about NHibernate proxies here: http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx
Upvotes: 1