tags:

views:

61

answers:

2

This is a brief description of my db. You have issues which have categories. I have various queries that get issues based on all sorts of criteria, but that's not important to the question.

I want to be able to take a list of issues I have queried, lets say for example, that occured yesterday and group them by category.

I have a method:

    public static IEnumerable<Category> GroupIssuesByCategory(IEnumerable<Issue> issues)
    {
        return from i in issues
               group i by i.Category into c
               select c.key
    }

Category has a nice mapping which allows it to list Issues within it. That's great for what I want, but in this scenario, it will pull back all the issues in that category, rather than the ones from the set I provided. How do I get around this?

Can I get around this?

A: 

I'm not sure about the second part of the question, but your compilation problem is that the return type of a grouping is IEnumerable>, which I think is what you are looking to return from your method. Also, you don't really need the 'into c select c' bit - that's only useful if you want to do some processing on the result of the grouping to get a different list.

IGrouping has a Key property which is the Category value, and is IEnumerable to give you the list of Issues in that Category.

Try this as your method:

public static IEnumerable<IGrouping<Category, Issue>> GroupIssuesByCategory(IEnumerable<Issue> issues)
{
    return from i in issues
           group i by i.Category;
}
Matthew Wright
A: 

I worked out why my original code wasn't compiling and updated the question.

Alas, I still have my main problem :/

qui