I came across a scenario where I had to use Union all, how can I achieve so in LINQ to entities ?
Asked
Active
Viewed 5.6k times
2 Answers
75
Here is the answer you are looking for. Use the Concat keyword.
From the example:
var query = (from x in db.Table1 select new {A = x.A, B = x.B})
.Concat( from y in db.Table2 select new {A = y.A, B = y.B} );

Justin Pihony
- 66,056
- 18
- 147
- 180
-
2This is great. I mistakenly used query1.Union(query2). Seems logical, right? – SteveB May 02 '19 at 23:53
-
I'm voting for the other answer, since he beat you by one minute. – Matt Frear Mar 09 '23 at 01:03
7
I believe Concat
is what you're looking for.
var allResults = resultSet1.Concat(resultSet2);
Obviously, both result sets must use the same type. And I believe there my be other requirements about how the result sets are constructed in the first place, but I don't know all the details.

StriplingWarrior
- 151,543
- 27
- 246
- 315