开发者

List<Product>.Join(List<Order>, ...) is identical to List<Order>.Join(List<Product>, ...)?

开发者 https://www.devze.com 2023-01-20 13:43 出处:网络
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. Ass开发者_运维百科ume I have two list, List<Product> and Lis

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. Ass开发者_运维百科ume 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>, ...) 

?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消