我的任务是将一些T-SQL查询重构为LINQ。简单的join和left outer join很容易理解。这是我的代码:
string[] leftouter = new string[] { "a", "b", "c", "d", "e" };
string[] inner = new string[] { "a", "b" };
var q = from s1 in leftouter
join s2 in inner on s1 equals s2 into j
from sj in j.DefaultIfEmpty()
select string.Format("Outer: {0} Left: {1}", s1, sj)
输出结果为:
Outer: a Left: a
Outer: b Left: b
Outer: c Left:
Outer: d Left:
Outer: e Left:
这是一个简单的左连接。现在我想添加一个新数据集:
string[] rightouter = new string[] { "c", "d", "e" };
期望的输出是:
Outer: a Left: a Right:
Outer: b Left: b Right:
Outer: c Left: Right: c
Outer: d Left: Right: d
Outer: e Left: Right: e
我该如何重新格式化LINQ以解决这个输出问题?谢谢。
e
,当leftouter
和inner
都不包含e
? - MarcinJuraszek