c# - LINQ Select Many 语句

标签 c# linq

从 MSDN Linq 运算 rune 章中我发现了以下声明。我

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 }; 

我的问题是,如果没有为客户和订单编写任何 where 或 join 条件,它将如何仅显示大于 2000.0M 的订单。该语句不会创建交叉连接吗?

最佳答案

不,该查询与此等效:

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 }; 
    }
}

所以没有加入。您只是过滤订单

关于c# - LINQ Select Many 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27695919/

相关文章:

c# - 小计关系数据表

c# - 从不同集合中删除另一个列表的对象列表

c# - AcadApplication for AutoCAD 2022 的位置和使用

c# - 如何从 C# 代码运行 NUnit 测试

c# - 根据字符串中定义的数据类型在运行时生成结构

.net - IEnumerable 为空?

c# - iSCSI 驱动器的 DriveInfo

c# - DGV CellPainting 行为异常

c# - 使用表达式树为新类创建 Lambda 表达式选择器

c# - 当对象类型在编译时未知时如何构建 LINQ 查询