Inheritance mapping with Fluent NHibernate
Posted
by Berryl
on Stack Overflow
See other posts from Stack Overflow
or by Berryl
Published on 2010-04-07T15:35:32Z
Indexed on
2010/04/08
18:13 UTC
Read the original article
Hit count: 478
Below is an example of how I currently use automapping overrides to set up a my db representation of inheritance. It gets the job done functionality wise BUT by using some internal default values. For example, the discriminator column name winds up being the literal value 'discriminator' instead of "ActivityType, and the discriminator values are the fully qualified type of each class, instead of "ACCOUNT" and "PROJECT".
I am guessing that this is a bug that doesn't get much attention now that conventions are preferred, and that the convention approach works correctly. I am looking for a sample of usage.
Cheers,
Berryl
public class ActivityBaseMap : IAutoMappingOverride<ActivityBase>
{
public void Override(AutoMapping<ActivityBase> mapping)
{
...
mapping.DiscriminateSubClassesOnColumn("ActivityType");
}
}
public class AccountingActivityMap : SubclassMap<AccountingActivity>
{
public AccountingActivityMap() {
...
DiscriminatorValue("ACCOUNT");
}
}
public class ProjectActivityMap : SubclassMap<ProjectActivity>
{
public ProjectActivityMap() {
...
DiscriminatorValue("PROJECT");
}
}
© Stack Overflow or respective owner