tags:

views:

36

answers:

1

Up to now, when doing join operation in LINQ, I have no idea how to decide which list must come first and which list must come after. Assume I have two list, List<Product> and List<Order>.

Edit:

My confusion is to decide

List<Product>.Join(List<Order>, ...) 

or

List<Order>.Join(List<Product>, ...) 

?

+1  A: 

Enumerable.Join performs an inner, equijoin. From MSDN:

'Inner' means that only elements that have a match in the other sequence are included in the results. An 'equijoin' is a join in which the keys are compared for equality.

Consequently, the choice of which sequence is deemed to be the 'outer' one has no impact on the items that will be present in the result of the query. All (outer, inner) pairs for which their respective projections are equal will make their way in.

However, there will be an impact in terms of the sequencing of items in the result. From MSDN:

Join preserves the order of the elements of outer, and for each of these elements, the order of the matching elements of inner.

Another trivial point is that switching 'outer' and 'inner' will mean the order of the delegate arguments will have to be swapped as well.

Ani