If you need to create a cross join in Entity Framework model, i.e. to link every record from the first table with every record from the second table, it can be implemented with a quite simple LINQ query.
In this example I use the same EF model with Client and Phone entities. LINQ query written in lambda syntax selects all possible pairs of client name and phone number.
1 2 3 4 |
var query31 = ctx.Clients .SelectMany( client => ctx.Phones.Select(phone => new { client.Name, phone.Number }) ); |
This query generates the following T-SQL code:
1 2 3 4 5 6 |
SELECT 1 AS [C1], [Extent1].[Name] AS [Name], [Extent2].[Number] AS [Number] FROM [dbo].[Clients] AS [Extent1] CROSS JOIN [dbo].[Phones] AS [Extent2] |