Thanks for your insights!
The things I'm mapping is the Id and foreign key. I've hacked my way around all of this by implementing IJoinedSubclassConvention like this:
public class JoinedSubclassConvention : IJoinedSubclassConvention
{
private static readonly IList<ClassMapping> joinedSubclasses;
static JoinedSubclassConvention()
{
joinedSubclasses = new List<ClassMapping>();
}
public static void Add<T>(AutoMapping<T> mapping)
{
ClassMapping classMapping = ((IMappingProvider)mapping).GetClassMapping();
joinedSubclasses.Add(classMapping);
}
public void Apply(IJoinedSubclassInstance instance)
{
string id = joinedSubclasses
.Where(mapping => mapping.Type == instance.EntityType)
.Select(mapping => mapping.Id).OfType<ColumnBasedMappingBase>()
.SelectMany(mapping => mapping.Columns)
.Where(column => column.Name != null && column.Name.EndsWith("Id"))
.Select(idColumn => idColumn.Name)
.FirstOrDefault();
if (id != null)
{
instance.Key.Column(id);
}
if (instance.EntityType.IsAbstract)
instance.Abstract();
}
}
And then in all IAutoMappingOverride implementations, I do this:
public void Override(AutoMapping<X> mapping)
{
// Do the mapping
JoinedSubclassConvention.Add(mapping);
}
It's lots of things that can be done in IAutoMappingOverride that isn't taken into consideration in my JoinedSubclassConvention, but this works for Id and foreign keys at least. I would love if this part of FNH could get some love in the future and I would be more than happy to test anything that improves on how this works at the moment.
Just being able to more easily figure out what an IAutoMappingOverride has done, and be able to extract this would be awesome. Even more awesome would be if IAutoMappingOverride would actually be useful for subclass-mapped entities, so when calling mapping.Id(x => x.Id, "MyId"), the ID column is named "MyId", etc.
--
Asbjørn Ulsberg -=|=-
asb...@ulsberg.no«He's a loathsome offensive brute, yet I can't look away»