Discriminate Sub Classes only for known types
I have a class mapped to a table and I'd like to create subclasses for some (but not all) of the values in one of the columns. Is this possible? For unknown values (those I don't specify as discriminator values) I'd like the base class to be used. I can see there's a
DiscriminatorPart.Default()
method, what does this do?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by James Gregory on 19 Feb, 2010 11:26 AM
I believe that method is for setting the default value for the column during schema generation.
I'm not certain if NHibernate supports a catch-all discriminator; normally you need to supply a specific value for the base-class discriminator, even if that value is
null
.Unless one of the other guys can shed some light on this, I suggest that you try using the overload to
DiscriminateSubClassesOnColumn
which allows you to set the base-class discriminator value and see how NHibernate behaves with any values you haven't declared.3 Posted by fluxmunki on 19 Feb, 2010 11:41 AM
Thanks, didn't spot the base class discriminator overload. I still can't find a way to make it work with unknown values. NH throws an exception for the first unknown discriminator value. I think it's an NH limitation.
I'm now thinking I'll just use a different design.
Support Staff 4 Posted by James Gregory on 19 Feb, 2010 11:46 AM
Yeah, I'm fairly certain NHibernate needs to know about every possible value
in that column. I would suggest adjusting your design to accommodate this.
James Gregory closed this discussion on 19 Feb, 2010 12:06 PM.