Microsoft LINQ Books

Programming Microsoft LINQ & Introducing Microsoft LINQ
Welcome to Microsoft LINQ Books Sign in | Join | Help
in Search

Listing 4-38

Last post 03-23-2010, 10:10 by Grigory. 0 replies.
Sort Posts: Previous Next
  •  03-23-2010, 10:10 179

    Listing 4-38

    According the book the listing 4-38 is:

                var expr = from p in products

                           join o in

                               (from c in customers

                                from o in c.Orders

                                join p in products on o.IdProduct equals p.IdProduct

                                select new { p.IdProduct, OrderAmount = o.Quantity * p.Price })

                           on p.IdProduct equals o.IdProduct into orders

                           select new { p.IdProduct, TotalOrderedAmount = orders.Aggregate( 0m, ( a, o ) => a += o.OrderAmount ) };

    we could avoid the outer join:

                var expr = from p in products

                                     join order in

                                         (from c in customers

                                          from o in c.Orders

                                          select new { c.Name, o.IdProduct, o.Quantity }) on p.IdProduct equals order.IdProduct into porder

                                     select new { p.IdProduct, Sum = porder.Aggregate(0m, (accum, order) => accum += order.Quantity * p.Price ) };

     

    Filed under:
View as RSS news feed in XML
Powered by Community Server (Personal Edition), by Telligent Systems