Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple levels of inheritance with Fluent NHibernate using discriminators

I'm in the enviable situation of having to integrate with a legacy database, luckily for readonly purposes, and have chosen to use NHibernate. Up until now everything has been great, but I have a new requirement which has me scratching my head.

Before today I had one column in the table that would act as a discriminator, but now it turns out that in some cases I need to have more than one discriminator column. Is this possible with NHibernate?

I've looked into using formulas, which works, but now I have the issue that I need to exclude 'unknown' subclasses (ones that don't yet have a mapping). For example I have this:

DiscriminateSubClassesOnColumn("")
    .Formula("case ... when ... then ... when .. then ... else 'unknown' end");

I'd like to be able to filter out everything that is 'unknown'...

Edit: I think that a possible solution would be to use AlwaysSelectWithValue(), what implications does enabling this have? I believe it's the same as force in the nhibernate mapping xml.

like image 795
jonnii Avatar asked Nov 16 '11 16:11

jonnii


1 Answers

public BaseClassMap()
{
    Where("discriminatorColumn <> 'unknown'");
    // or
    Where("discriminatorColumn = 'known1' or discriminatorColumn = 'known2'");
}
like image 175
Firo Avatar answered Sep 28 '22 11:09

Firo