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.
public BaseClassMap()
{
Where("discriminatorColumn <> 'unknown'");
// or
Where("discriminatorColumn = 'known1' or discriminatorColumn = 'known2'");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With