Question

I'm having an issue with Fluent NHibernate AutoPersistenceModelGenerator. It doesn't want to pick up custom maps.

Using Sharp Architecture 2.0, Fluent NHibernate 1.2 and NHibernate 3.1.

My current relevant configuration is as follows:

    public AutoPersistenceModel Generate()
    {
        // This mappings group works with the exception of custom maps!!
        var mappings = AutoMap.AssemblyOf<SecurableEntity>(new AutomappingConfiguration());
        mappings.Conventions.Setup(GetConventions());
        mappings.IgnoreBase<Entity>();
        mappings.IgnoreBase<SecurableEntity>();
        mappings.IgnoreBase(typeof(EntityWithTypedId<>));
        mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

        //mappings.UseOverridesFromAssemblyOf<UserMap>(); // Should call Override method of UserMap, but doesn't appear to...
        mappings.Override<User>(new UserMap().Override()); // This hack fixes the issue with calling the Override method of UserMap.
        mappings.UseOverridesFromAssemblyOf<UserMap>();

        return mappings;
    }

class UserMap : IAutoMappingOverride<User>
{
    public void Override(AutoMapping<User> mapping)
    {
        //mapping => mapping.Table("Users");
        mapping.Table("Users");
    }

    public Action<AutoMapping<User>> Override()
    {
        return map =>
            {
                map.Table("Users");
            };
    }
}

I've tried making various modifications to the configuration and pouring over internet articles on Fluent NHibernate, to no avail. I have a working version using Sharp Arch 1.x, and earlier versions of NHibernate and Fluent. I'm assuming that there has been a change in syntax that I'm missing. Any and all help would be greatly appreciated.

Thank you! John

Was it helpful?

Solution

Fluent NHibernate use Assembly.GetExportedTypes() method to get all the overrides from given assembly. As this method's documentation say, it gets the public types defined in this assembly that are visible outside the assembly. Your override is implicitly internal. Just add public before class UserMap and it'll work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top