Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7040841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:57:59+00:00 2026-05-28T01:57:59+00:00

I have an array called dbRecipes which contains a list of recipes divided into

  • 0

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:

var groups = (from g in dbRecipes orderby g.Group.GroupOrder select g.Group).Distinct();
foreach (var g in groups)
{
   output.Write("{0}<br/>", g.GroupName);

   var recipes = (from r in dbRecipes where r.Group == g orderby r.DisplayOrder select r.Recipe);
   foreach(var r in recipes)
   {
      output.Write("---{0}<br/>", r.Title);
   }
}

This seems to work fairly well, but is there a way to do this that’s perhaps more efficient, cleaner, or doesn’t require multiple queries? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:57:59+00:00Added an answer on May 28, 2026 at 1:57 am
    var groups = 
        from r in dbRecipes
        orderby r.DisplayOrder
        group r by r.Group into g
        orderby g.Key.GroupOrder
        select g;
    
    foreach (var g in groups) 
    { 
       output.Write("{0}<br/>", g.Key.GroupName); 
    
       foreach(var r in g) 
       { 
          output.Write("---{0}<br/>", r.Recipe.Title); 
       } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array (called array in the code below) which contains a number
I have an array called list, for example list = [0,1,2,3] in the HTML
I have a array called $A which contains only non zero positive numbers. Now
I have an array called $times . It is a list of small numbers
I have a pretty simple problem. Basically I have an array called $list that
I have an array list called str, i want to see how many elements
I have an array list called str, i want to see the elements inside
I have a 2D array called results. Each row array in results contains both
I have a string array variable called 'myAttachmentArray[]' which holds different figures like this:
I have an array which contains numbers like 331,554,22 or it could be 45,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.