Skip to content

Instantly share code, notes, and snippets.

@dotsonjb14
Last active August 29, 2015 14:15
Show Gist options
  • Save dotsonjb14/edbc402cfa3e02e6f188 to your computer and use it in GitHub Desktop.
Save dotsonjb14/edbc402cfa3e02e6f188 to your computer and use it in GitHub Desktop.
Adventure Sales by Year
var salesPeople =
Person
.Select(x => new { Name = x.FirstName + " " + x.LastName, x.BusinessEntityID });
SalesOrderHeader
.Where(x => x.OnlineOrderFlag == false)
.GroupBy(x => new { x.OrderDate.Year, x.SalesPersonID })
.Select(x => new {
Key = x.Key,
Sales = x.Sum(y => y.SubTotal)
})
.Select(x => new { Year = x.Key.Year, SalesPerson = salesPeople.FirstOrDefault(y => y.BusinessEntityID == x.Key.SalesPersonID).Name, Sales = x.Sales })
.OrderByDescending(x => x.Sales)
.GroupBy(x => x.Year)
.OrderBy(x => x.Key)
.Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment