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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:47:08+00:00 2026-05-24T01:47:08+00:00

I have tree structure table like, Table{Id, ParentId, Name} where Id is primary key,

  • 0

I have tree structure table like,

Table{Id, ParentId, Name}

where Id is primary key, and parent Id is a foreign key, but to the same table. It will have values like

Id            ParentId             Name
1              -                          N1

2              1                          N2

3              1                          N3

4              2                          N4

here, N2 and N3 is child of N1, and N4 a child of N2

I am using Entity framework and MVC to build rest like webservice.

How can I use entity framework to recursively to get all child nodes?

  • 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-24T01:47:09+00:00Added an answer on May 24, 2026 at 1:47 am

    How can I use entity framework to recursively to get all child nodes?

    EF doesn’t have support for recursive queries. You can map such structure easily as referenced by @Eranga in comment but once you load entities you must either manually define eager loading (= you must say how deep it should go) or your child entities will be loaded by lazy loading first time they are accessed (that is extremely inefficient).

    The best way to work with hierarchical structures in EF is either using database view to hide hierarchical SQL query or using SQL / stored procedures directly.

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

Sidebar

Related Questions

I have a table with tree structure: id parentId name ---------------- 1 0 Category1
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
I have a tree-style database with the following structure: Table fields: NodeID int ParentID
I have a table in my database which stores a tree structure. Here are
I have a table in SQL server that has the normal tree structure of
I have a tree structure in memory that I would like to render in
I have the need to return tree like results from a single table. At
I have a simple tree structure represented like this: Node { int Id; int
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to
I have a tree data structure that is L levels deep each node has

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.