如何将此表达式转换为 LEFT JOIN
var query = order.Items.Join(productNonCriticalityList,
i => i.ProductID,
p => p.ProductID,
(i, p) => i);
如何将此表达式转换为 LEFT JOIN
var query = order.Items.Join(productNonCriticalityList,
i => i.ProductID,
p => p.ProductID,
(i, p) => i);
这是使用 Lambda 表达式编写它的更复杂的方法:
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
}
)
from
语法,并使用into
关键字。它与方法语法执行的功能相同,但更易读(依我之见)。(from l1 in myFirstDataSet
join l2 in mySecondDataSet on l1.<join_val> equals l2.<join_val> into leftJ
from lj in leftJ.DefaultIfEmpty()
where <your_where_clause>
select <something>).ToList();
GroupJoin
。使用查询语法并非必须。 - Servy