如何使LEFT JOIN在Lambda LINQ表达式中 [英] How to make LEFT JOIN in Lambda LINQ expressions

查看:300
本文介绍了如何使LEFT JOIN在Lambda LINQ表达式中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使此表达式为LEFT JOIN

How to make this expression as LEFT JOIN

var query = order.Items.Join(productNonCriticalityList,
    i => i.ProductID,
    p => p.ProductID,
    (i, p) => i);


推荐答案

这是使用lambda表达式更复杂的方法写:

And this is the more complicated way using lambda expressions to write it:

order.Items
   .GroupJoin (
      productNonCriticalityList, 
      i => i.ProductID, 
      p => p.ProductID, 
      (i, g) => 
         new  
         {
            i = i, 
            g = g
         }
   )
   .SelectMany (
      temp => temp.g.DefaultIfEmpty(), 
      (temp, p) => 
         new  
         {
            i = temp.i, 
            p = p
         }
   )

这篇关于如何使LEFT JOIN在Lambda LINQ表达式中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆