c# - Is there a way to combine two LINQ queries into one?

问题描述:

I have an array called dbRecipes which contains a list of recipes divided into groups. For example, the Dinner group might have a stuffed salmon, a salad, and mashed potatoes. The dessert group would have a chocolate molten lava-cake. Mmmm.

I need to display these recipes in a grouped list, such as:

Group 1:

- Recipe 1

- Recipe 2

Group 2:

- Recipe 3

Each item in dbRecipes contains a Group property which contains information about which group it's in, and a Recipe property which contains information on the recipe.

I'd like to use a LINQ query to iterate through the whole thing, but I'm far from a LINQ expert so the best way I've found is to query for all the distinct groups, then loop through each one of those. Here's my code: