Lambda Left Join

时间:2017-02-28 02:04:51

标签: c# linq lambda

我有一个LINQ查询,我想在执行左连接后处理NULL值。

我有以下代码:

var leftjoinlist = listA.GroupJoin(
        listB,
        a => a.Code,
        b => b.Code,
        (a, g) => g
    .SelectMany(new { Parent = a, Child = b })
    .DefaultIfEmpty(new { Parent = a, Child = a }))
    .SelectMany(g => g).ToList();

如果child为null,我想改为指定父级。但是,我在分配期间收到转换错误。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

这是在您的情况下具有外部左连接的正确语法:

$scope.mailing.secondary_committee = data.split(',');// service data