2

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

user1003221
  • 453
  • 1
  • 5
  • 17

1 Answers1

4

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.

NOtherDev
  • 9,542
  • 2
  • 36
  • 47
  • Wow, I apologize for that one. It's hard to believe i worked on that for so long without noticing the missing public access modifier... – user1003221 Oct 21 '11 at 17:54
  • If you find the answer helpful, upvote it. If it solves your problem, mark it as answer. Thanks! – NOtherDev Oct 21 '11 at 18:52
  • A very helpful answer. `Conventions.AddFromAssemblyOf` handles internal types all right, so I would never ever think that `UseOverridesFromAssemblyOf` can't do it. It's rather inconsistent. – Sergei Tachenov Jul 16 '16 at 11:39