SubclassMap fluent mapping ignored when mixed with automapping
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?
Support Staff 2 Posted by James Gregory on 18 May, 2010 06:50 PM
You are incorrect, I'm afraid.
From the wiki:
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 usingSubclassMap
, you won't get "overriding" behaviour.This is something we're looking to fix in whatever release follows 1.1.
3 Posted by MylesRip on 18 May, 2010 08:46 PM
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:
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?
Support Staff 4 Posted by James Gregory on 19 May, 2010 01:50 AM
I'm afraid the wiki is incorrect in this case.
SubclassMap
andComponentMap
are both entirely incompatible with the automapping. You should just be able to create an override for your subclass, I don't thinkSubclassMap
is necessary in this situation.