LINQ Select Many语句

Sun*_*nny 2 c# linq

来自MSDN Linq运营商的文章我发现如下声明.一世

https://code.msdn.microsoft.com/LINQ-to-DataSets-09787825

SelectMany - 来自作业

  var orders = 
        from c in customers 
        from o in c.Orders 
        where o.Total >= 2000.0M 
        select new { c.CustomerID, o.OrderID, o.Total }; 
Run Code Online (Sandbox Code Playgroud)

我的问题是没有为客户和订单写任何地方或加入条件,它如何只显示大于2000.0M的订单.该语句不会创建交叉连接.

Sel*_*enç 5

不,该查询对此非常重要:

foreach(var c in customers)
{
    foreach(var o in c.Orders)
    {
        if(o.Total >= 2000.0M)
           yield return new { c.CustomerID, o.OrderID, o.Total }; 
    }
}
Run Code Online (Sandbox Code Playgroud)

所以没有join.你只是过滤了orders.