Our objects have a group of common properties. To reduce duplicate mapping, I created a base ClassMap that displays identifiers and general properties. For each ClassMap object, I just subclass the database, and it works great. For a new project, we also let NH generate a DB schema for us. The problem is that the order of the columns is such that the properties from the base ClassMap class first appear, followed by everything that appears in the subclass. The requirement for this assembly is that the columns are displayed in a specific order.
To get around this, I did the following.
public class BaseMap<T> : ClassMap<T> where T : Entity { public BaseMap() { Id(x => x.Id); MapEntity(); Map(x => x.CommonProperty1); Map(x => x.CommonProperty2); Map(x => x.CommonProperty3); } protected virtual void MapEntity() { } } public class SomeEntityMap : BaseMap<SomeEntity> { public SomeEntity() { base.MapEntity(); } protected override void MapEntity() { Map(x => x.SomeEntityProperty1); Map(x => x.SomeEntityProperty2); Map(x => x.SomeEntityProperty3); } }
It works, but it feels like a hack. Besides the hacking factor, is there anything here that might be problematic?
source share