1. Concat
Single row concat
var expr = (from P in context. Products select P.productname) . Concat ( from C in context. Categories select C.categoryname ); foreach (var item in expr) {Console.WriteLine (item);}
var expr = context. Products = p.productname) . Concat ( context. Categories = c.categoryname) );
SELECT [UnionAll1].[ProductName] as [C1] from(SELECT [Extent1].[ProductName] as [ProductName] from [dbo].[Product] as [Extent1] UNION All SELECT [Extent2].[CategoryName] as [CategoryName] from [dbo].[Category] as [Extent2]) as [UnionAll1]
Multi-column Concat
var expr = context. Products new { p.productid, p.productname }) . Concat ( context. Categories new { = C.categoryid, = c.categoryname }) );
SELECT [UnionAll1].[ProductID] as [C1], [UnionAll1].[ProductID1] as [C2], [UnionAll1].[ProductName] as [C3] from(SELECT [Extent1].[ProductID] as [ProductID], [Extent1].[ProductID] as [ProductID1], [Extent1].[ProductName] as [ProductName] from [dbo].[Product] as [Extent1] UNION All SELECT [Extent2].[CategoryID] as [CategoryID], [Extent2].[CategoryID] as [CategoryID1], [Extent2].[CategoryName] as [CategoryName] from [dbo].[Category] as [Extent2]) as [UnionAll1]
2. Union
var expr = context. Products = p.productname) . Union ( context. Categories = c.categoryname) );
SELECT [Distinct1].[C1] as [C1] from(SELECT DISTINCT [UnionAll1].[ProductName] as [C1] from(SELECT [Extent1].[ProductName] as [ProductName] from [dbo].[Product] as [Extent1] UNION All SELECT [Extent2].[CategoryName] as [CategoryName] from [dbo].[Category] as [Extent2]) as [UnionAll1] ) as [Distinct1]
LINQ series: LINQ to SQL concat/union