Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate FluentMappings.AddFromAssemblyOf<> Issue

A coworker and I were recently doing the backend for a small application using Fluent NHibernate. We wrote our entities, mapping files, persistence manager, but for some reason we couldn't export the database schema to anything.

Through the debugger we discovered that the FluentMappings.AddFromAssemblyOf was returning 0 mappings, even though they are clearly there, and clearly correct. We tried everything we could think of, and ended up having to do add each mapping manually.

The following is the code that did not work:

        return Fluently.Configure().Database(
            MsSqlConfiguration.MsSql2005
                .ConnectionString(c => c
                .TrustedConnection()
                .Server("localhost")
                .Database("LDTT")))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())
            .ExposeConfiguration(BuildSchema)
            .BuildSessionFactory();

Whereas this code did work:

        return Fluently.Configure().Database(
            MsSqlConfiguration.MsSql2005
                .ConnectionString(c => c
                .TrustedConnection()
                .Server("localhost")
                .Database("LDTT")))
                .Mappings(m => m.FluentMappings.Add<ClientMap>())
                .Mappings(m => m.FluentMappings.Add<ContactMap>())
                .Mappings(m => m.FluentMappings.Add<DepartmentMap>())
                .Mappings(m => m.FluentMappings.Add<DivisionMap>())
                .Mappings(m => m.FluentMappings.Add<FileMap>())
                .Mappings(m => m.FluentMappings.Add<FileTypeMap>())
                .Mappings(m => m.FluentMappings.Add<RegionMap>())
                .Mappings(m => m.FluentMappings.Add<TimeEntryMap>())
                .Mappings(m => m.FluentMappings.Add<UserMap>())
            .ExposeConfiguration(BuildSchema)
            .BuildSessionFactory();

Does anyone know why this happens, and how to fix it?

like image 507
Cody Avatar asked May 27 '09 21:05

Cody


1 Answers

Make UserMap a public type.

like image 194
Darin Dimitrov Avatar answered Nov 03 '22 11:11

Darin Dimitrov