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 4611098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:13:20+00:00 2026-05-22T01:13:20+00:00

Well I have this: Board: public class Board { public int BoardID { get;

  • 0

Well I have this:
Board:

    public class Board
{
    public int BoardID { get; set; }
    public string BoardName { get; set; }
    public string BoardDescription { get; set; }
    public int PostCount { get; set; }
    public int TopicCount { get; set; }
    public bool IsVisibile { get; set; }
    public Forum BelongToForum { get; set; }
    public List<Board> Boards { get; set; }
    public List<Topic> Topics { get; set; }
}

And Forum:

    public class Forum
{
    public int ForumID { get; set; }
    public string ForumName { get; set; }
    public string ForumDescription { get; set; }
    public List<Board> Boards { get; set; }
}

And method that get Forums with boards:

        public List<Forum> GetForums()
    {
        List<Forum> forums = new List<Forum>();
        _ctx = new ForumContext();
        forums = (from p in _ctx.Forums
                  select p).ToList();
        List<Forum> returnForm = new List<Forum>();
        foreach(Forum forum in forums)
        {
            List<Board> board = (from x in _ctx.Boards
                                 where x.BelongToForum.ForumID == forum.ForumID
                                 select x).ToList();
            forum.Boards = board;

            returnForm.Add(forum);
        }


        return returnForm;
    }

It’s working as expected. But as you see I’m using three lists, and foreach loop. It doesn’t look really good for me. So I have an question, is there another way to make it work ?

I think I should made another model class that will gather nessesary data from join or something like this.
But what I want to ask are there other ways to do it ?

  • 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-22T01:13:20+00:00Added an answer on May 22, 2026 at 1:13 am

    If you look at your Forum entity it already has a Boards property. You should be able to materialize those in one query using Include().

     forums = (from p in _ctx.Forums.Include("Boards")
               select p).ToList();
    

    Or using the strongly typed Include():

     forums = (from p in _ctx.Forums.Include( x=> x.Boards)
               select p).ToList();
    

    Can you clarify whether this is code first or DB first? From your example it looks like DB first with POCO models (with code first the Boards property should have been materialized already since it is not marked as virtual).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
Well i have this set of codes <?php include includes/config.php; class template{ var $page;
Well I have this code in my Managed C++/Cli in Visual Studio 2008, I
Well currently I have this: <rich:fileUpload addLabel=Agregar clearAllLabel=Quitar todos clearLabel=Quitar deleteLabel=Quitar doneLabel=Completado uploadLabel=Subir archivos
I have this routine that works well, but it messes up as it counts
I have this linq query that works well (although it may be written better,
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
Well this is weird let me describe the scenario I have this mailer define
I have this structure in my html document: <p> <em>You</em> began the evening well,
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,

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.