C# – Fluent NHibernate FluentMappings.AddFromAssemblyOf<> Issue

cfluent-nhibernatenhibernateorm

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?

Best Answer

Make UserMap a public type.

Related Topic