SubclassMap fluent mapping ignored when mixed with automapping

MylesRip's Avatar

MylesRip

18 May, 2010 06:11 PM via web

I have a SubclassMap that I am mixing in with the automappings. The subclass represents a single class within an inheritance hierarchy. The rest of the hierarchy is handled by automapping.

In this SubclassMap, I have a component nested inside another component and I'm trying to set the column name for one of the properties in this nested component.

I have set a breakpoint within the SubclassMap at the following line and have confirmed that it is being executed.

m1.Map(z => z.LegalSubDivision).Column("To_DlsLocation_LegalSubDivision");

When I inspect the generated hbm file, however, I see that the column name override is being ignored and the column is simply being mapped as "LegalSubDivision".

Am I incorrect in assuming that the SubclassMap should override the automapping?

  1. Support Staff 2 Posted by James Gregory on 18 May, 2010 06:50 PM

    James Gregory's Avatar

    You are incorrect, I'm afraid.

    From the wiki:

    Note: The automapper is not aware of SubclassMap's. You will need to manually exclude any types you've mapped as subclasses before the automapper will work correctly with them.

    You should be able to ignore the subclass type using the ShouldMap(Type) configuration; however, you will have to map the subclass in its entirety using SubclassMap, you won't get "overriding" behaviour.

    This is something we're looking to fix in whatever release follows 1.1.

  2. 3 Posted by MylesRip on 18 May, 2010 08:46 PM

    MylesRip's Avatar

    I overrode ShouldMap(Type) in the automapping configuration to exclude the subclass that I want to handle with the fluent mapping. The result was that automapping simply moved the property mappings for the properties of that subclass to each of the subclasses that derive from it. ( The subclass I'm overriding is in the middle of the hierarchy. )

    The fluent mapping is still being executed, but does not affect the generated hbm.

    This seems like a good time to confirm a related question one way or the other... Given the following:

    return Fluently.Configure() 
        .Database(persistenceConfigurer) 
        .Mappings(m => 
            {
                m.FluentMappings.Add<LinearPropertyItemMap>().ExportTo("C:\\Temp\\hbm\\fluent");
                m.AutoMappings.Add(
                           model.AddEntityAssembly(typeof(EntityBase).Assembly)
                           ...
                           .UseOverridesFromAssemblyOf<PropertyMappingOverride>()
                           ).ExportTo("C:\\Temp\\hbm\\auto");
            }) 
        .ExposeConfiguration(BuildSchema) 
        .BuildSessionFactory();
    

    Note that there are two "ExportTo" calls, one for fluent mappings and one for automappings, that write to two different directories. When I run this, nothing gets generated in the directory for the fluent mappings. The generated hbm files for the automappings do not reflect what was (or should have been) mapped from the fluent mapping. What is the expected behavior in this situation?

  3. Support Staff 4 Posted by James Gregory on 19 May, 2010 01:50 AM

    James Gregory's Avatar

    I'm afraid the wiki is incorrect in this case. SubclassMap and ComponentMap are both entirely incompatible with the automapping. You should just be able to create an override for your subclass, I don't think SubclassMap is necessary in this situation.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the number before twelve?