tags:

views:

573

answers:

2

Is it possible to have a discriminator that works like this with NHibernate?

If the value equals String.Empty --> Class1 Else --> Class2

I already have a string column for CultureName and I would like to use it as a discriminator. I don't want to add an extra boolean column. If the CultureName is String.Empty then I would like to one class, else another one.

If it is not possible, could you help me find a way to do this.

I'm using xml mappings (not Fluent NHibernate).

What I'm searching for is something like a wildcard for the else (default) case so I can map like this :

<subclass name="Class1" discriminator-value="">
<subclass name="Class2" discriminator-value="*">
A: 

you should check out the table-heirarchy mapping strategy specified here which specifies how you can use a discriminator column for your class mappings.

lomaxx
Thanks for your answer but I've already checked the documentation... my question is for the special case that I've described : if one value (String.Empty in this case) then Class1 else Class2.
W3Max
+4  A: 

You can add a discriminator forumla to the primary class

<discriminator formula="case when discriminatorID = '' then 1 else 2 end"/>

then

<subclass name="Class1" discriminator-value="1">

<subclass name="Class2" discriminator-value="2">

Trent