November 2017
Intermediate to advanced
800 pages
30h 51m
English
There are LINQ extension methods to perform aggregation functions, such as Average and Sum.
Add some new statements, as shown in the following code, to the bottom of the Main method to show the use of the aggregation extension methods:
WriteLine("Products");WriteLine($" Count: {db.Products.Count()}");WriteLine($" Sum of units in stock: {db.Products.Sum(p => p.UnitsInStock):N0}");WriteLine($" Sum of units on order: {db.Products.Sum(p => p.UnitsOnOrder):N0}");WriteLine($" Average unit price: {db.Products.Average(p => p.UnitPrice):$#,##0.00}");WriteLine($" Value of units in stock: {db.Products.Sum(p => p.UnitPrice * p.UnitsInStock):$#,##0.00}");
Run the console application and view the output:
Products Count: 77 Sum of ...
Read now
Unlock full access