LinqPad 的 lambda 窗口有什么用?

发布于 2024-12-28 18:47:47 字数 56 浏览 1 评论 0原文

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

I may be being stupid but never seem to get anything showing in the 'lambda window' after running code. Can anyone explain how it is supposed to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2025-01-04 18:47:47

如果您使用查询语法编写查询,则 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)
}

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

If you write a query using query syntax, the lambda window will translate the query into method syntax.

Try running the sample "What about LINQ to SQL?" in the LINQPad 5 minute induction* folder in the samples tab. (induction = LINQPad typo, not mine!)

Your code window will look like this:

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

and the lambda window will look like this:

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)))
         }
   )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文