score:3
Accepted answer
You could try something like this:
data.GroupBy(d => new { Hometeam = d.Hometeam, Outteam = d.Outteam })
.Select(g => g.OrderBy(d => d.Status)
.ThenByDescending(d => d.GoalsHometeams + d.GoalsOutteams)
.First())
- Groups by the team combinations
- For each group, finds the entry with the newest status (
Confirmed
comes beforeOpen
in alphabetical order) - If multiple with same status (i.e., multiple
Open
), finds entry with highest combined score. - Grabs the first result (which should be newest) per group.
Demo: http://ideone.com/vlCtw
Sample Result:
Current game status results:
Confirmed, Fylkir, Valur, 3, 1
Confirmed, Selfoss, Grindavik, 3, 3
Confirmed, Keflavik, IBV, 1, 0
Confirmed, Stjarnan, IA, 1, 1
Confirmed, Breioablik, Fram, 0, 2
Source: stackoverflow.com
Related Query
- Linq distinct by multiple columns and pick the newest row
- C# Linq How to select the distinct row count of multiple columns in a datatable
- LINQ to SQL Select Distinct by Multiple Columns and return entire entity
- C# Linq to select multiple columns by group and apply sum(aggregate function) on value field at the same time
- How can I return all the columns of a table using multiple distinct columns in Linq
- LINQ - GroupBy multiple columns and merge the result
- LINQ query returning the entire object grouped by multiple columns when one is distinct
- Distinct on Multiple Columns Entity Framework LINQ
- Selecting multiple columns with linq query and lambda expression
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- LINQ to DataSet, distinct by multiple columns
- Does this LINQ code perform multiple lookups on the original data?
- Group by multiple columns linq count nested row
- How do I order the elements in a group by linq query, and pick the first?
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- linq group by and select multiple columns not in group by
- LINQ to SQL join 3 tables and select multiple columns and also using Sum
- How do I calculate a checksum on all columns in a row using LINQ and Entity Framework?
- Linq To Sql Search Multiple Columns and Multiple Words
- Linq GroupBy and multiple columns
- C# Linq Join 2 tables on multiple columns and GROUP BY for count
- IEqualityComparer and Linq Distinct - Hard Code GetHashCode()
- Using Linq to group by multiple columns in a list and mark all duplicate items
- How to aggregate the value from DISTINCT row using LINQ
- Joining two tables and returning multiple records as one row using LINQ
- Use Linq to filter on distinct options and newest date
- How to retrieve one table row and list of rows that are connected to the first row in Linq .NET
- linq distinct on two columns and return as a single field
- Linq Groupby multiple columns with the same name (An anonymous type cannot have multiple properties with the same name)
- Using LINQ with stored procedure that returns multiple instances of the same entity per row
More Query from same tag
- How to combine 2 linq statments with groupby clause into 1
- Create Numeric Contain Expression with reflection in c#?
- Getting error when fetching data from Sql server compact using linq
- Is it possible to have Thread.Sleep() in a single List<T> ForEach?
- Where list contains any in List
- LINQ to dictionary
- Group by single column in Linq c#
- c# Intersection and Union not working correctly
- Problems with casting LinQ result to strongly typed collection
- How to join multiple 1 to many relationship tables using NHibernate
- Buttons list bind to Grid into UserControl (WPF, Linq, Buttons)
- How do you populate a parent child data structure from XML where generic List<> objects are in parent and child structures using one LINQ query?
- Using linq to get list of web controls of certain type in a web page
- Difference between Where and Single
- Where clause on list property
- Convert IEnumerable<T> to collection of dynamically generated objects
- Is there way to get the max value from YYYYMM combination?
- OFFSET in LINQ to SQL
- Linq To Sql Search Multiple Columns and Multiple Words
- LINQ to XML - Load node then add to Xdocument - Namespace issue
- How to dynamically add descending to orderby?
- How do I mimic the functionality of IQueryable<T>.Include(Expression<Func<T,TProperty>> path) in my custom collection?
- Using linq how do i remove multiple records from a cross reference table
- Select if exist XML Element using LINQ
- Linq min date max date model querying
- Convert to Int with LINQ
- how to store dbcontext.emps.ToList() data in a data table
- How to call a lambda using LINQ expression trees in C# / .NET
- SQL to LINQ handling Match in Left outer JOIN
- Entity Framework multi table query