score:1
Accepted answer
you can group by a string
produced from your list items taken in the same order. assuming that '|'
character is not allowed inside names, you can do this:
var namelist = json_converted
.groupby(n => string.join("|", n.names.orderby(s => s)))
.select(g => new {
name = g.first().names
, count = g.count()
});
this approach constructs a string "a|b"
from lists ["a", "b"]
and ["b", "a"]
, and use that string for grouping the content.
since the keys are composed of ordered names, g.first().names
used as name
may not be in the same order for all elements of the group.
score:1
you can write a comparer for the list of names.
public class namescomparer : iequalitycomparer<ienumerable<string>>
{
public bool equals(ienumerable<string> x, ienumerable<string> y)
{
//do your null checks
return x.sequenceequal(y);
}
public int gethashcode(ienumerable<string> obj)
{
return 0;
}
}
then use that in groupby:
var namelist = json_converted.groupby(n => n.names, new namescomparer())
.select(i => new { name = i.key, count = i.count() });
Source: stackoverflow.com
Related Query
- Linq groupby list matching and count
- How make a LINQ Select, GroupBy and Count from a List of Lists?
- Combining GroupBy and Count of items matching a criteria in LINQ
- Linq List problems with GroupBy and Count
- LINQ with groupby and count
- compare two list and return not matching items using linq
- LINQ with subselect and groupby to get only the latest version of each item in a list
- GroupBy String and Count in LINQ
- LINQ DynamicLibrary: How to extract count and list from IQueryable
- C# - Linq optimize code with List and Where clause
- Linq Query Count and GroupBy
- Best way to join 3 lists and count how many times an ID is in the list using linq
- List Categories and it's count of products with LinQ using Lambda or classic expressions
- C# JSON.Net parse and get list of all elements matching a value using LINQ
- EF core Linq groupby and having sum count - could not be translated and will be evaluated locally
- Linq to entities query that returns a count and a list of objects
- GroupBy using LINQ but base distinct on another column, and still be able to count other records
- Returning list of count and grouped by id linq to sql
- Linq groupby and count operations in mvc
- Different result in Linq with GroupBy and Count
- c# linq if item is in list and get matching items from list
- GroupBy and Count with condition using LINQ
- LINQ GroupBy and project to type with both a list of its keys and result of ToDictionary
- GROUPBY and SUM on List items using LINQ
- GroupBy and Count using LINQ
- C# LINQ code for two list compare and replace
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- C# Linq Group elements from list and count sum of values
- Convert SQL to Linq - Where, in, Groupby and Having count
- I want to print Count using Groupby and Left join in linq
More Query from same tag
- Is it wise to use LINQ to replace loops?
- Get the max date from linq with mutiple joins and with multiple select fields
- How to pass lambda expressions as parameter in C#
- Will LINQ to SQL use defered execution when we map the result to an object?
- How to build a sequence using a fluent interface?
- Dealing with nulls indynamically created linq expression
- How to linq OrderBy on a nested table field?
- Query Not Working for All (in Hash)
- Filter List to the same list using Linq
- Confused on c# lambda expression with Linq
- MongoDB Linq driver casting exception
- Random 2-D array with LINQ c#
- Getting Time Series for a certain item with LINQ
- EF6 query building to get the first object in the list
- How to write this LINQ ( or SQL) query?
- LINQ left outer join on date not working
- How to not print duplicates in a data grid view using LINQ
- LINQ Update query with Join condition
- Linq DateTime Difference sum
- Is there any default order in which where clause in LINQ query filters sequence
- Retrieving entities from a one to many relationship (Odata)
- Calculated property with Linq Expression
- Dynamics CRM Linq validation
- Expression Func with two input parameters for generic method
- Linq and group by clause
- How to C# linq GroupBy multiple arrays with array values
- Check null values in Linq query in Entity Framework
- Using Count() function throws “Internal .NET Framework Data Provider error 1025.”
- select A where A < B in LINQ
- What is the right way to show only group by column in datatable