LinqPad 的 lambda 窗口有什么用?



我可能很愚蠢,但在运行代码后,似乎从未在"lambda窗口"中显示任何内容。有人能解释一下它应该如何工作吗?

如果使用查询语法编写查询,lambda窗口将把查询转换为方法语法。

尝试在samples选项卡中的LINQPad 5分钟归纳*文件夹中运行示例"What about LINQ to SQL?"。(归纳=LINQPad打字错误,而不是我的!)

您的代码窗口将如下所示:

    from p in Products
let spanishOrders = p.OrderDetails.Where (o => o.Order.ShipCountry == "Spain")
where spanishOrders.Any()
orderby p.ProductName
select new
{
    p.ProductName,
    p.Category.CategoryName,
    Orders = spanishOrders.Count(), 
    TotalValue = spanishOrders.Sum (o => o.UnitPrice * o.Quantity)
}

λ窗口将如下所示:

Products
   .Select (
      p => 
         new  
         {
            p = p, 
            spanishOrders = p.OrderDetails.Where (o => (o.Order.ShipCountry == "Spain"))
         }
   )
   .Where (temp0 => temp0.spanishOrders.Any ())
   .OrderBy (temp0 => temp0.p.ProductName)
   .Select (
      temp0 => 
         new  
         {
            ProductName = temp0.p.ProductName, 
            CategoryName = temp0.p.Category.CategoryName, 
            Orders = temp0.spanishOrders.Count (), 
            TotalValue = temp0.spanishOrders.Sum (o => (o.UnitPrice * (Decimal?)(o.Quantity)))
         }
   )

相关内容

  • 没有找到相关文章

最新更新