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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:39:32+00:00 2026-06-11T01:39:32+00:00

I have a self-referencing table structure working fine with EF, which I use to

  • 0

I have a self-referencing table structure working fine with EF, which I use to render a tree view. The EF entity looks like the following and I eagerly load the total structure.

class ListItem
{
  int Id;
  string Text;
  ListItem ParentItem;
  IList<ListItem> ChildItems;
}

Then I added the functionality on the UI to add new child nodes to any node and rearranging the nodes using jQuery. The updated structure is stored in the session using the same entity.

When I want to save it back using EF, I ran into problems as I have it inside another entity like the following, and I am saving(updating) this MainEntity whenever I want to update the tree.

class MainEntity
{
  ..
  ..
  IList<ListItem> Tree;
}

How can I update this Tree property using the values from my session and tell EF to save it? How can I change the parents and children of that structure to match the new structure?

I was thinking of using command pattern to record every action of the UI and replay them later on the EF entity on save. But that looks like an overkill 🙁

  • 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-11T01:39:33+00:00Added an answer on June 11, 2026 at 1:39 am

    After days of trying out different things in vain I finally implemented command pattern and got it working as expected.

    I implemented the following command interface for Add, Update, Delete and Reorder UI actions and stuff them in a collection which resides in the session.

    public interface ITreeCommand
    {
        void Execute(ICollection<ListItem> finalList, MainEntity source, ModelContainer db, ICollection<Guid> deletedIds);
    }
    

    Then on save, I execute these commands in order passing necessary parameters. I had to call db.SaveChanges() inside every execute method implementation. I had to keep the deleted node ids separately because I can skip any unnecessary additions, updates or reordering by checking against this list before executing.

    Hope this helps someone someday.

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

Sidebar

Related Questions

I have inherited a legacy application which makes use of a self-referencing table to
I have a self referencing table in Oracle 9i, and a view that gets
I have a self-referential table in my database that looks sort of like above.
I have a standard self referencing table of Categories . In my entity model
I have a self-referencing many-to-many relationship between users and managers that looks like this:
I have a problem in a hierarchical query. I have a self-referencing table like
I have a self referencing table Product with the following structure (where D =
I have a self-referencing table with content like this: Self-referencing parent table ID ParentID
I have a self referencing table as covered in the doctrine documentation (which is
I have a self referencing table named categories that has a parentcategoryid column that

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.