2
I need to implement a query
in nhibernate make a union
between 2 tables. In sql, it would be something like that:
SELECT T1.Id AS ID
FROM TABELA1 AS T1
UNION
SELECT T2.Id AS ID
FROM TABELA2 AS T2
I couldn’t find any way to make one union
, nor with QueryOver
, nor with Linq
.
Someone knows something that can help me?
Edit 1
With Linq
I even came up with an "almost" solution, but an error occurred saying that Union
is not supported by nhibernate. What I did was this:
var query = (from t1 in Session.Query<Tabela1>()
select t1.Id
).Union(from t2 in Session.Query<Tabela2>()
select t2.Id);
query.ToList();
The mistake was this:
The Unionresultoperator result Operator is not Current supported
I don’t even know which way to go now, maybe I’ll have to do both selects
separated and the union
in remembrance.
Yes I’ve seen some people doing this, but I’m building a web service, to control synchronization of local data (legacy system) with a remote sales system (offline), and I need this
union
for query of deleted or inattentive items in the system. And so I have 2 queries, one for deleted in an audit table, which stores the identifiers of the deleted records, by period, and another for the records marked with an inactive database flag, also filtered by period. Then this query will be for a large amount of entities.– Fernando Leal
I’m testing the case of doing in memory following this issue of SOEN, in the answer accepted. I made an example here and apparently it is working perfectly, but even so it would be better to do it directly in the database. But every tip to improve is welcome. I’ll take a look at the tip you went through and see if it’s better for my case.
– Fernando Leal