score:1
the easiest way is probably to "flatten" the problem and then do the group by:
var query = officers.selectmany(
x => new[] {
new { x.name, ro = x.reportingofficer1 },
new { x.name, ro = x.reportingofficer2 },
new { x.name, ro = x.reportingofficer3 }
}
);
var grouped = query.groupby(y => y.ro);
foreach (var group in grouped) {
foreach (var item in group) {
console.writeline(string.format("{0}: {1}", item.ro, item.name));
}
}
here, i am assuming officers
is a ienumerable<officer>
where
class officer {
public string name { get; set; }
public string reportingofficer1 { get; set; }
public string reportingofficer2 { get; set; }
public string reportingofficer3 { get; set; }
}
with your sample data this is my output:
john: a
john: b
jack: a
rob: a
rob: c
earl: b
carl: b
carl: d
chris: c
kenny: c
rodney: d
jacob: d
Source: stackoverflow.com
Related Query
- Group By either column using C# LINQ
- How to calculate count on of table column using group by clause in linq
- How to group an SQL date column stored as int as Year Month using LINQ
- Group by column and get first record of group using Linq
- Group DataSet Column Values into Comma Separated String using LINQ
- Group by one column and Distinct by another column using Linq
- Getting all elements while using group by on string column using LINQ
- select more column not in group by using linq in c#
- Possible to add two columns together and group by that column using linq on IQueryable?
- Get the specific count of each column using GROUP BY LINQ
- Group rows with identical value into column using LINQ
- GROUP BY in datatable on two columns with sum of third column using LINQ
- Using LinQ with group by more than one column
- Using Linq First Group particular Column value and then Make Avg of values from second column
- datatable sum column and concatenate rows using LINQ and group by on multiple columns
- Calculate sum of column using group by in Linq
- Select column from group using linq
- Convert string[] to int[] in one line of code using LINQ
- Using Linq to group a list of objects into a new grouped list of list of objects
- How to get first record in each group using Linq
- LINQ to SQL using GROUP BY and COUNT(DISTINCT)
- Select All distinct values in a column using LINQ
- Counting Using Group By Linq
- Using LINQ to group a list of objects
- Using LINQ to group by multiple properties and sum
- how to group by multiple columns using linq
- Group by variable integer range using Linq
- Exclude a column from a select using LINQ
- Linq to SQL using group By, and order by count
- Group alternate pairs using LINQ
More Query from same tag
- Filter generic list with generic dictionary
- Needing Help Utilizing Linq with lists vb net
- Linq casting between types
- how to remove duplicate data for group query in Linq
- How do i traverse through an xml document that has identical elements?
- Remove comments from file
- C++/CLI Lambda Selector for LINQ Static Methods
- How to select items from IEnumerable?
- Read an XML node value using Linq
- Sum of varchar field in linq , how to do conversion
- Delete FileInfo using LINQ
- Linq Selecting rows from a view?
- Case sensitive in linq Query
- How can apply a group by to a result of another group by using MongoDb?
- Partial Record Updates with Linq to SQL and MVC
- Is IEnumerable<T> Replace bad design?
- Property casting in linq expression
- How to read XML via c# such as <Mode Name="text">
- DATEDIFF (in months) in linq
- Linq-to-SQL combobox binding
- Linq Table to DataTable casting
- How to cast query to query of another interface to add constrainst based on that
- Is it possible to evaluate a string containing valid LINQ dynamically / at runtime?
- LINQ - group specific types of classes
- Find collections intersection and exclude
- How do I convert SQL Query with Ccase Switch to Linq Lambda
- Union of two linq statement
- how can i select all name into one group at the same class?
- Entity framework select with group by
- How can we get list of two column say firstname and lastname from customer table in mvc using linq query