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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:50:39+00:00 2026-06-02T23:50:39+00:00

I am working in an ASP.NET project with EF and I have some trouble

  • 0

I am working in an ASP.NET project with EF and I have some trouble with finding a correct query.
I need to work without lazy-loading.

I have following data structure:
A Module contains pages.
A Page contains PageItems.
A PageItem contains an Item.
An Item can contains other Items.

Leaving out the recursive aspect of Items containing Items at first, I need a query to feed the structure of a single module into a treeview.

What I want is :

  • The Module with the given ID
    • Including all pages
      • Including all PageItems
        • Including all Items with ParentItem_ID == 0
          • Including all ChildItems

I started with this:

return base._entities.Modules
            .Include(m => m.Paginas
                .Select(p => p.PaginaItems
                    .Select(pi => pi.Item)
                    .Select(i => i.ChildItems)))
            .Where(m => m.Module_ID == id)
            .FirstOrDefault();

This query works, but it ignores the item-hierarchy and displays all items as direct child of a page. What would actually need is something like this:

return base._entities.Modules
           .Include(m => m.Paginas
               .Select(p => p.PaginaItems
                   .Select(pi => pi.Item)
                   .Where(i => i.I_ParentItem_ID == 0)
                   .Select(i => i.ChildItems)))
           .Where(m => m.Module_ID == id)
           .FirstOrDefault();

But it does not work.

I an relatively new to LINQ, and any help would really be appreciated.

  • 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-06-02T23:50:40+00:00Added an answer on June 2, 2026 at 11:50 pm

    As you need a condition in a nested collection you should use join, like:

    (from mod in c.Modules
    join pag in c.Paginas on mod.Module_Id equals pag.Module_Id
    join pi in c.PaginaItems on pag.Pagina_Id equals pi.Pagina_Id
    join item in c.Items.Where(i => i.I_ParentItem_ID == 0) on pi.PaginaItem_Id
        equals item.PaginaItem_Id
    join ci in c.ChildItems on item.I_ParentItem_ID equals ci.I_ParentItem_ID
    select mod).FirstOrDefault()
    

    I abbreviated base._entities to c (for context) and made some assumptions about Id names and possibly overlooked the odd syntax error, but this should be a good start.

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

Sidebar

Related Questions

On a recent project I have been working on in C#/ASP.NET I have some
I'm working on an ASP.NET web project using VS2010/C#, I have some text boxes
background:Me and my coworkers are working on asp.net mvc project ... we have a
I'm working on asp.net (vb, maybe that can change something) I have a project
I'm working in an ASP.NET MVC project where I have created a two LinqToSQL
I am working on a personnel asp.Net project that has some calender based events.
I'm working on asp.net (C#) project which include some page files (aspx, aspx.cs) and
Now I have to fix some bugs in MVC.Asp.Net project. In projec i have
I'm working on an ASP.Net MVC project and have been learning a few little
I'm currently working on an ASP.NET MVC project using NHibernate and I need to

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.