0

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 };
Freshblood
  • 6,285
  • 10
  • 59
  • 96
  • why did you label the question as "entity-framework"? maybe you are using linq in entity framework but this is a general linq question not ef. – erasmus Jun 10 '10 at 09:20
  • Yes, i thought what u have said.I am not expert and i have never used joining in normal linq queries when i start to learn Entity framework i saw it and thought that join method can dependenices on EF.Now i understand it is not EF question so i am removing that tag now. – Freshblood Jun 10 '10 at 09:37

2 Answers2

5

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
  • 732,580
  • 175
  • 1,330
  • 1,459
1

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

erasmus
  • 925
  • 2
  • 9
  • 16
  • 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 Jun 10 '10 at 09:22
  • 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 Jun 10 '10 at 09:40
  • 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 Jun 10 '10 at 09:56
  • 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 Jun 10 '10 at 10:11