Nhibernate.class equivalent in QueryOver

Below are the HQL queries for a specific type of class.

select a from Animal a
where TYPE(a) in ('Cat', 'Dog')
and a.sex = 'Male'
order by a.name


select a from Animal a
where a.class in ('Cat', 'Dog')
and a.sex = 'Male'
order by a.name

I am wondering if there is an equivalent using QueryOver?

+5
source share
1 answer

You can use the QueryOver GetTypeextension IsInmethod to accomplish this:

session.QueryOver<Animal>()
    .Where(a => a.GetType().IsIn(new[] { "Cat", "Dog" })
    /* .. etc */

You must use the discriminator values ​​that your NHibernate mapping uses.

+5
source

All Articles