Where the sentence with the check type "is" the operator does not use the discriminator

I have mapped the class hierarchy in NHibernate. Plain:

class abstract Animal
class Dog : Animal
class Cat: Animal
class Cow: Animal

In the mapping, I have the discriminator values ​​set in the ANIMAL_TYPE column:

Dog -> dog
Cat -> cat
Cow -> cow

All kinds of queries work. Other than that, when I need to get objects of two specific types. I wrote like this:

QueryOver.Of<Animal>().Where(animal => animal is Dog || theme is Cat)

And I do not get any results. When I look at the generated request, NHibernate generates:

(this_.ANIMAL_TYPE = @p0 or this_.ANIMAL_TYPE = @p1)

which is great, but the values ​​in the parameters @ p0 and @ p1 contain the full name of the class, for example.

Zoo.Model.Cat

instead of the discriminator values. How can i solve this? Should I keep discriminator values ​​in sync with type names? I would like to avoid this if possible.

+3
1

: QueryOver ? ( )

var query = session.QueryOver<Animal>()
    .Where(animal => animal.GetType() == typeof (Dog) 
                  || animal.GetType() == typeof (Cat)
          );

var list = query.List<Animal>();
+3

All Articles