【问题标题】:How can I convert this linq expression to method form?如何将此 linq 表达式转换为方法形式?
【发布时间】:2011-10-12 04:24:53
【问题描述】:

我怎样才能转换这个 linq

from f in fake
join r in real
on f.Year equals r.Year
into joinResult
from r in joinResult.DefaultIfEmpty()
select (r == null ? f : r);

在带有方法形式的 Linq 中。

fake.Join(real, ...)

有什么工具可以帮助我做到这一点吗?

【问题讨论】:

    标签: c# linq linq-expressions


    【解决方案1】:

    这是 ReSharper 将其转换成的:

    fake.GroupJoin(real, f => f.Year, r => r.Year, (f, joinResult) => new {f, joinResult})
        .SelectMany(@t => @t.joinResult.DefaultIfEmpty(), (@t, r) => (r == null ? @t.f : r));
    

    【讨论】:

      猜你喜欢
      • 2020-01-13
      • 2010-12-04
      • 2013-10-02
      • 2022-01-19
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-26
      相关资源
      最近更新 更多