c# - LINQ2SQL - More Questions on when a Cross join with where clause is emitted instead of Inner Join -


This is a question of two questions and instead of trying to find a solution to the problem, for educational purposes.

I have already seen it and it is feeling that it is similar to my question

But I will tell you more information from LINQ and SQL Gurus the'm hoping Why LINQ2 SQL is designed to internally join rather than cross connect Additionally, that it can tell the link to the SQL server execution plan (or more ), Why these two questions Arises similar plan ? What I think, this means that the performance of questions is the same.

I have created a small example that runs two LINQ expressions on my database which generates these two separate SQL queries.

For those people who do not want to bother, here is my example DB diagram:

These are two questions: Where the cross joins var q = context.Items former new equivalent {ITEM_ID = i_mem items. RelatedItemID, user_id = i_mem.RelatedUserID} sq_i_m.DefaultIfEmpty () to join i_cat sq_i_cat selection context.Categories on item.RelatedCategoryID in sq_i_m from im equals i_cat.ID in sq_i_cat the proj item;

Inner Join

  context.Items joining the i_mem in context.Memberships new items {ITEM_ID = item.ID, user_id = current_user_id.Value} equals new {ITEM_ID = i_mem.RelatedItemID, user_id = i_mem.RelatedUserID} (sq_i_m from im in sq_i_m.DefaultIfEmpty) select i_cat.ID join i_cat in context.Categories on item.RelatedCategoryID Item equals   

and if you want to see for yourself then the exam program is.

Thanks for everyone's help.

Mustafa

This is the same thing, so it does not matter Which emits LINQ2SQL

a internal included rationally a where contains internal section

That is why the Sql server generates the same query plan

Obviously, joining the internal:. In

  f1 combination based on the inner T 2 T1 selection T1.k = T2.k where T1.f2 as 'X%'   

Cross Is similar to joining:

  Select T1 cross from F1  
  Select: Where T1.k = T2.k and T1.f2 'X% '  

The old style is similar to SQL, such as joining T2 from F1 to T1, T2, where T1K = T2K and T1F 2 like 'x%'

Comments