什么是LinqPad的lambda窗口?

Joe*_*ett 7 linq linqpad

我可能是愚蠢的,但在运行代码后似乎永远不会在'lambda窗口'中显示任何内容.任何人都可以解释它应该如何工作?

Jon*_*ell 13

如果使用查询语法编写查询,则lambda窗口会将查询转换为方法语法.

尝试运行示例"LINQ to SQL怎么样?" 在样本选项卡中的LINQPad 5分钟感应*文件夹中.(感应= 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)
}
Run Code Online (Sandbox Code Playgroud)

lambda窗口看起来像这样:

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)))
         }
   )
Run Code Online (Sandbox Code Playgroud)