Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is LinqPad's lambda window for?

Tags:

linq

linqpad

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?

like image 794
Joe Fawcett Avatar asked Jan 25 '12 12:01

Joe Fawcett


1 Answers

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)))
         }
   )
like image 110
Jon Crowell Avatar answered Dec 14 '22 06:12

Jon Crowell