11

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?

Jon Crowell
  • 21,695
  • 14
  • 89
  • 110
Joe Fawcett
  • 307
  • 2
  • 7

1 Answers1

15

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)))
         }
   )
Jon Crowell
  • 21,695
  • 14
  • 89
  • 110
  • Thanks. Needless to say as soon as I posted I tried a few of the samples and found results in the lambda window. However I didn't quite realise why until I read your explanation. It was just unlucky that all the examples I had tried originally used the method syntax. – Joe Fawcett Jan 25 '12 at 13:13