Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhibernate .class equivalent in QueryOver

Below are HQL queries for specific type of classes

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

Im wondering is there and equivalent using QueryOver?

like image 251
reggieboyYEAH Avatar asked Jul 16 '12 00:07

reggieboyYEAH


1 Answers

You can use GetType with the IsIn QueryOver extension method to accomplish this:

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

You should use the discriminator values that your NHibernate mapping uses.

like image 84
Andrew Whitaker Avatar answered Nov 01 '22 06:11

Andrew Whitaker