Nhibernate queryover union

506 Views Asked by At

I have two queries based in session.QueryOver. The queries are different, but returns a IList the same type object. The number of result of the two query, is the total object that i need.

How can I combine both queryover?

Is possible to do a union in NHibernate?

1

There are 1 best solutions below

0
YYTan On

You could consider using CreateSQLQuery instead. Form your SQL query syntax with the UNION keyword and use CreateSQLQuery to execute your query and get your result.

ISessionFactory.OpenSession().CreateSQLQuery("SELECT * FROM A UNION SELECT * FROM B")
                             .SetResultTransformer(Transformers.AliasToBean(typeof(YourClass)))
                             .List<YourClass>();