How to create a query with union using NHibernate

2

I need to implement a query in to do a union between 2 tables. In , it would look something like this:

SELECT T1.Id AS ID
FROM TABELA1 AS T1
UNION    
SELECT T2.Id AS ID
FROM TABELA2 AS T2

I did not find any way to make a union , neither with QueryOver , nor with Linq .

  

Does anyone know anything that can help me?

Edit 1

With Linq until I got a "almost" solution, more error occurred saying that Union is not supported by

asked by anonymous 03.04.2014 / 19:42

1 answer

1

If you have control over the database, you could create a view in the database, make the union , and then map a class of your to the view. That would solve the problem.

If it's not that way, I guess just doing it in memory.

According to this answer in SOEN , you can use the Future method to make two queries on the same call to the bank , which would be better than making two distinct calls. Still, all results would be returned, without deleting duplicates, which would have to be done in memory .

var resultSet1 = this.Session.CreateCriteria<A>().Future<A>();
var resultSet2 = this.Session.CreateCriteria<B>().Future<B>();

Unfortunately, according to this other SOEN response , you can not use Future with LINQ, until version 3, so it seems the only way at the moment is to use the syntax above.

    
04.04.2014 / 01:36