score:4
Accepted answer
var q = from i in crimes
group i by i.Date.ToString("MMM") into grp
select new {Month = grp.Key, Count = grp.Sum(i => i.Persons)};
score:0
List<Crime>() crimes = ...
var crimesPerMonth = crimes.GroupBy(x => x.Date.Month);
score:11
crimes.GroupBy(c => c.Date.Month)
.Select(g => new { Month = g.Key, Count = g.Count() });
Source: stackoverflow.com
Related Articles
- c# Linq or code to extract groups from a single list of source data
- LINQ Source Code Available
- Linq: Totals Groups By Month
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- How to write SQL translateable linq code that groups by one property and returns distinct list
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ group by then order groups of result
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How to use LINQ to order within groups
- Syntax to execute code block inside Linq query?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Linq group month by quarters
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- LINQ recursive query to return hierarchical set of groups
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ list of sublist
- how to read value from a session object
- Define a list type into a variable
- SQL to Linq conversion - Max(), Groupby, Limit/page
- Can we add new elements to a list using Parallel.ForEach()?
- How to find the second greatest element in a list with LINQ
- Is there anything that is possible in LINQ but not Lambda?
- Is there any way to make right to left value assigning in linq or in any other way
- Linq query correction
- Count the specific feature in gridview using linq
- How to get first level of children by LINQ
- Fill List<T> with IEnumerable<T> when projecting a new type using LINQ
- How to grasp all C# functional features?
- Group by not including "null" data
- Using linq to retrieve pairs of Points from collection?
- Identical (?) C# and VB.NET LINQ queries return different results
- Anonymous type and LINQ and casting
- Linq Entity Framework - get all customers that Ids are not in many to many table
- Getting character values in Linq to Entities
- SubSonic 3 Linq Join Problems