Linq solution to union two select statements
-
I just discovered how to do this and thought I'd share it as I couldn't find it with google search for 'linq union' I wanted to reproduce the following SQL script using linq. select a, b, c from table1 union select a, b, c from table2 to do this in linq: var mainQuery = (from t1 in context.table1 select t1).AsEnumerable().Union(from t2 in context.table2 select t2).AsEnumerable(); :)
-
I just discovered how to do this and thought I'd share it as I couldn't find it with google search for 'linq union' I wanted to reproduce the following SQL script using linq. select a, b, c from table1 union select a, b, c from table2 to do this in linq: var mainQuery = (from t1 in context.table1 select t1).AsEnumerable().Union(from t2 in context.table2 select t2).AsEnumerable(); :)
Very nice, but you should probably add this as a tip or trick.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility