fluent-nhibernateschemapocoautomapping

Is it possible to use both automapping and schema generation with Fluent NHibernate?


I'm using the following:

Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString))
        .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Incident>()
        .Where(t => t.Namespace.StartsWith("EDA.DomainModel.POCO"))))
        .ExposeConfiguration(BuildSchema)
        .BuildSessionFactory();

It's essentially a copy of what's in the Fluent NHibernate wiki. However, whenever I run this line, it throws out this InnerException:

"The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided. A generic argument must be provided for each generic parameter."

I'm really not sure what the problem is, so I'm wondering if Fluent NHibernate can do automapping together with schema generation in the first place. What I want to do is just create a persistence layer for the POCO's without having to see the database or fool around with any tables whatsoever.


Solution

  • Yes it is possible. I use automapping and do export schema. As for that the exception I got it when I tried to map IDictionary<,>. Do you use it? Does Fluent NHibernate work at all - even if you don't try to export schema? I'd say that it's a problem with your mappings, not with schema export. If you have IDictionary then it's almost for sure. Try to nail down your schema to trivial classes and see if it helps; try to create database schema manually (for trivial classes it's simple) and check if it works then.