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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:56:35+00:00 2026-06-10T21:56:35+00:00

Been struggling with this on an architectural level. I have an object which can

  • 0

Been struggling with this on an architectural level.

I have an object which can be commented on, let’s call it a Post. Every post has a unique ID.

Now I want to comment on that Post, and I can use ID as a foreign key, and each PostComment has an ItemID field which correlates to the Post. Since each Post has a unique ID, it is very easy to assign “Top Level” comments.

When I comment on a comment however, I feel like I now need a PostCommentComment, which attaches to the ID of the PostComment. Since ID’s are assigned sequentially, I can no longer simply use ItemID to differentiate where in the tree the comment is assigned. I.E. both a Post and a Post Comment might have an ID of ‘5’, so my foreign key relationship is invalid.

This seems like it could go on infinitely, with PostCommentCommentComment’s etc…

What’s the best way to solve this? Should I have a field in the comment called “IsPostComment” or something of the like to know which collection to attach the ID to? This strikes me as the best solution I’ve seen so far, but now I feel like I need to make recursive DataBase calls which start to get expensive.

Meaning, I get a Post and get all PostComments where ItemID == Post.ID && where IsPostComment == true

Then I take that as a collection, gather all the ID’s of the PostComments, and do another search where ItemID == PostComment[all].ID && where IsPostComment == false, then repeat infinitely.

This means I make a call for every layer, and if I’m calling 100 Posts, I might make 1000 DB calls to get 10 layers of comments each.

What is the right way to do this?

  • 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-10T21:56:37+00:00Added an answer on June 10, 2026 at 9:56 pm

    I’d say that you would just have PostComment, not PostCommentComment or anything beyond that.

    All PostComments have a PostId, so when you load comments for that post, you just query by PostId.

    All comments also have ParentId, which points to another comment (top-level comments will not have a ParentId). In this way, every comment can have comments on it to any depth, but the data remains flat in the database.

    Once you load all comments with a given PostId, you can assemble the tree/hierarchy in memory using the ParentId property.

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

Sidebar

Related Questions

Has been struggling on this for a week I have two classes WiFiScanReceiver which
Have been struggling with this for a while, and can never seem to get
I've been struggling with this for a while. Basically, I want to have two
I have been struggling with this for a while now. given a set of
I have been struggling with this error for more than two hours: error: aggregate
I've been struggling with this for several hours and can't seem to figure out
So I've been struggling with this for a couple days now. I have a
I've been struggling with this for days and I can't figure out why it
I've Been struggling with this in the past hour. Can someone help me to
I have been struggling with this problem for a few days now and I

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.