Using C# linq, How can i group by specific item in array?
I have an array of Project objects.
IEnumerable<Project> projects = GetProjects();
Each Project has a property called "Applications" which is an array of
strings.
IEnumerable<string> applicationsForProject = project.Applications();
Some projects have 1 application (1 element in the array) but others have
many.
I want to group all of my projects by individual application so I can
generate a view that looks like this:
App 1: 10 projects
App 2: 4 projects
App 3: 5 projects
If i do this:
var projectsByApp = projects.GroupBy(r=>r.Applications);
that will group not by the distinct applications but by the list so I wind
up getting duplicate rows in my view (since project 1 might have App1 and
App 2 and project 2 might just have App 2)
Is there any better way to group by distinct application name across the
array of projects?
No comments:
Post a Comment