Friday, February 18, 2011

LINQ to objects : The impact of join order

Here's the sample syntax of the join clause:

var expr = from a in collectionA
           join b in collectionB
                on a.AKey equals b.BKey
           ...


Notes:

  • equals is a contextual keyword specifically for LINQ. 
  • In the on section the first rangeItem (a) Must come before the second rangeItem (b) . Otherwise the query will not compile. 
  • Internally for LINQ to objects the first collection is looped storing the hash for each Key. And then the second item is looped computing the hash and comparing it to the first item. So the output will contain order of the items in the first collection :)

Enjoy!



No comments:

Post a Comment