LINQ in Action - LINQ Book & News

Calculating baseball statistics with Linq

If you are fed up with the obligatory business use cases used in Linq samples - you know, the Customers and Orders guys from the Northwind database - you may be interested in seeing less boring queries.
Derek Slager has published some Linq queries he wrote to calculate baseball stats.
Example:

var battingAverageLeaders =
  from game in games
  from play in game.GetPlays()
  where play.Result != null
  group play by play.Batter into g
  where g.Count(p => p.Result.IsAtBat) > 400
  let pd = new PlayerData {
    Player = g.Key,
    Data = (Math.Round(1000.0d *
                ((double)g.Count(p => p.Result.IsHit) /
                 (double)g.Count(p => p.Result.IsAtBat))) / 1000.0d).ToString(".000") }
  orderby pd.Data descending
  select pd;
Published Thursday, October 12, 2006 4:13 PM by Fabrice Marguerie

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Linq in Action News said:

Do you want to see LINQ used for something else than querying a database for customers or for querying

March 28, 2007 2:16 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Featured Item

This Blog

Sponsoring

Syndication

Tags

No tags have been created or used yet.