This question is actually very good in these two.
INNER JOIN ON vs WHERE clause
INNER JOIN and several table names in the FROM clause
I included two examples of how three different LINQ expressions will be translated into SQL.
Implicit join:
from prod in Articles from kat in MainGroups where kat.MainGroupNo == prod.MainGroupNo select new { kat.Name, prod.ArticleNo }
Will be translated into
SELECT [t1].[Name], [t0].[ArticleNo] FROM [dbo].[Article] AS [t0], [dbo].[MainGroup] AS [t1] WHERE [t1].[MainGroupNo] = [t0].[MainGroupNo]
Internal connection:
from prod in Articles join kat in MainGroups on prod.MainGroupNo equals kat.MainGroupNo select new { kat.Name, prod.ArticleNo }
Will be translated into
SELECT [t1].[Name], [t0].[ArticleNo] FROM [dbo].[Article] AS [t0] INNER JOIN [dbo].[MainGroup] AS [t1] ON [t0].[MainGroupNo] = [t1].[MainGroupNo]
Left outer join:
from prod in Articles join g1 in MainGroups on prod.MainGroupNo equals g1.MainGroupNo into prodGroup from kat in prodGroup.DefaultIfEmpty() select new { kat.Name, prod.ArticleNo }
Will be translated into
SELECT [t1].[Name] AS [Name], [t0].[ArticleNo] FROM [dbo].[Article] AS [t0] LEFT OUTER JOIN [dbo].[MainGroup] AS [t1] ON [t0].[MainGroupNo] = [t1].[MainGroupNo]
If you want to check how your expressions will be translated into SQL, I recommend that you try LINQPad . This is a terrific tool for figuring out these kinds of things.
source share