Search code examples
nhibernatenhibernate-mappinghqlqueryover

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?


Solution

  • 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.