LINQ - Using where or join - Performance difference ?

Posted by Patrick Säuerl on Stack Overflow See other posts from Stack Overflow or by Patrick Säuerl
Published on 2010-06-10T12:02:23Z Indexed on 2010/06/10 12:13 UTC
Read the original article Hit count: 186

Filed under:

Hi

Based on this question: http://stackoverflow.com/questions/3013034/what-is-difference-between-where-and-join-in-linq

My question is following:

Is there a performance difference in the following two statements:

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,UrunAdi=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,UrunAdi=product.Name };

I would always use the second one just because it´s more clear.

My question is now, is the first one slower than the second one? Does it build a cartesic product and filters it afterwards with the where clauses ?

Thank you.

© Stack Overflow or respective owner

Related posts about LINQ