How can I do a Union all in Entity Framework LINQ To Entities?

Rami Sakr picture Rami Sakr · Mar 22, 2012 · Viewed 45.4k times · Source

I came across a scenario where I had to use Union all, how can I achieve so in LINQ to entities ?

Answer

Justin Pihony picture Justin Pihony · Mar 22, 2012

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} );