Stopping LINQ from querying objects (and grouping)

This is a quick summary of my db. You have problems with categories . I have different queries that cause problems based on different criteria, but this is not important to the question.

I want to have a list of questions that I asked, say, for example, what happened 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
}

      

The category has a nice mapping that allows it to list issues within it. This is great for what I want, but in this case it will undo all problems in that category, not the ones from the set I provided. How do I get around this?

Can you get around this?


I figured out why my original code doesn't compile or update the question.

Alas, I still have a basic problem.

0


source to share


1 answer


I'm not sure about the second part of the question, but the compilation issue is the return type of the grouping IEnumerable<IGrouping<Category, Issue>>

, which I think is what you want to return from your method. Also, you don't need a bit into c select c

, which is only useful if you want to do some processing on the result of the join to get another list.

IGrouping<S,T>

has a key property, which is a value Category

, and is IEnumerable<T>

to provide you with a list Issues

in this 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;
}

      

0


source







All Articles