问题
So I would like to have a BaseEntity which contains common columns that appear in all tables and use inheritance to keep mapping of these fields in one place. For the sake of simplicity I will only include one field (Id). The code looks as follows:
[Serializable]
public abstract class BaseEntity
{
public Guid Id { get; set; }
}
public class Hedge : BaseEntity
{
public virtual DateTime HedgeDate { get; set; }
public virtual DateTime SettleDate { get; set; }
}
public class Trade : BaseEntity
{
public virtual DateTime TradeDate { get; set; }
public virtual DateTime SettleDate { get; set; }
}
The Mapping looks as follows:
public class BaseEntityMap : ClassMap<BaseEntity>
{
public BaseEntityMap()
{
Id(x => x.Id).GeneratedBy.GuidComb();
UseUnionSubclassForInheritanceMapping();
}
}
public class HedgeMap : SubclassMap<Hedge>
{
public HedgeMap()
{
Map(x => x.HedgeDate);
Map(x => x.SettleDate);
}
}
public class TradeMap: SubclassMap<Trade>
{
public TradeMap()
{
Map(x => x.TradeDate);
Map(x => x.SettleDate);
}
}
To load the configuration I am using the following code:
Configuration cfg =
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(TestDatabaseConnection.ConnectionString))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<HedgeMap>()
).BuildConfiguration();
Now when I run my unit tests, the configuration is loaded and created successfully however the configuration is empty (no class maps). As far as I can tell I am following the documentation available on the fluent-nhibernate website. Does anyone know what I am doing wrong?
来源:https://stackoverflow.com/questions/8811181/cant-get-fluent-nhibernate-to-work-with-subclasses