tags:

views:

49

answers:

2

hello

What is difference between of these 2 queries ? they are completely equal ?

from order in myDB.OrdersSet
    from person in myDB.PersonSet
    from product in myDB.ProductSet
    where order.Persons_Id==person.Id && order.Products_Id==product.Id
    select new { order.Id, person.Name, person.SurName,  product.Model,UrunAdı=product.Name };

and

from order in myDB.OrdersSet
    join person in myDB.PersonSet on order.Persons_Id equals person.Id
    join product in myDB.ProductSet on order.Products_Id equals product.Id
    select new { order.Id, person.Name, person.SurName,  product.Model,UrunAdı=product.Name };
+4  A: 

The end result should be the same.

But using JOIN is clearer - it's more obvious what you're doing (joining three sets of data).

My personal "best practice" approach would be:

  • use WHERE to reduce and limit the number of rows returned - it's typically limiting one set of data (by defining some criteria to be met)

  • use JOIN to express the intent of joining two tables / sets of data together on a common field (or set of fields)

marc_s
+1  A: 

Join shows the relationship between table clearer and also in less keystrokes.

erasmus
This goes well with the LINQ philosophy: prefer code clarity to execution speed. Especially when there is no speed loss in the clearer code, of course :-)
Gorpik
These clarity can cause such questions as i asked.Because if where does all job of join so what is difference between of them .If there is no difference so why join is exist : )
Freshblood
the clarity is, when you use join, you use a higher abstraction. however, "where" is its underlying implementation. also, this is not linq's style of having where and join. it is because sql has both of them.
erasmus
Join has restriction for Table relationships when "where" hasn't.This would create problems. Join only accept "Equals" operator while "where" support many logical operators.
Freshblood