1

After extensive googling, I still can't find a definitive answer to this question. Some old articles/blog posts I've seen say not at all. Some say yes if the underling database supports it. Which is it? I asked on the nhusers group with no answer so far. Any help would be appreciated.

Jimit
  • 765
  • 2
  • 10
  • 18

3 Answers3

2

NHibernate does not support union. There is always one type in a result.

What you can do is a query to a base class or interface. NHibernate will perform a union to get all the values from all tables where the entities are mapped to.

There is also the union-subclass mapping strategy, which also implies that there is a base class or interface.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • Hey Stefan, by using interface/base class you mean using polymorphic queries, right? I followed the polymorphic strategy (one interface, two concrete classes) and the query works fine but IQueryable.Count() does not return the desired value. It only returns the count of the first type. I was wondering if you ever had such a problem? [I think the count issue might be related to NH-2500] – kaptan Sep 15 '12 at 02:16
  • I don't think that it is related to NH-2500 (https://nhibernate.jira.com/browse/NH-2500), which is related to query parameters. Most probably "select count" is just not implemented that way. I didn't find any resources for it. You may find it in the code. – Stefan Steinegger Sep 18 '12 at 09:39
1

HQL does not support union nor intersect. You probably can achieve it via Criteria or native SQL.

Source: https://www.hibernate.org/117.html#A21

o.k.w
  • 25,490
  • 6
  • 66
  • 63
0

I've read somewhere that it doesn't although I can't figure out why. the best way to see is to try it your self...

Dani
  • 14,639
  • 11
  • 62
  • 110
  • @Dani: Here!!! http://stackoverflow.com/questions/247103/how-do-you-do-a-union-of-two-tables-in-nhibernate – o.k.w Oct 29 '09 at 11:07