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

  • Home
  • SEARCH
  • 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 5976231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:11:56+00:00 2026-05-22T21:11:56+00:00

If I have one-to-many relation between two entities (ie. Post and Comment ) and

  • 0

If I have one-to-many relation between two entities (ie. Post and Comment) and have my master class defined as:

public class Post {
    ...
    IList<Comment> Comments { get; set; }
}

But my Comment sub-related class doesn’t have a property of type Post, because there’s never a need to get from comment to post. Comments are always displayed along with the master post instance.

Then I have a stored procedure that returns two result sets: posts and comments that are related to them. I define my MapResultSet as

MapResultSet[] sets = new MapResultSet[2];

sets[0] = new MapResultSet(typeof(Post), posts);
sets[1] = new MapResultSet(typeof(Comment));

sets[0].AddRelation(sets[1], /* what goes here? */, "PostID", "Comments");

But this doesn’t work, since Comment doesn’t have a reference to its Post hence I don’t have anything to define for the second parameter in the upper code. If I provide string.Empty or null I get an exception if invalid method parameter.

How should I define relationship between these two entities without adding a Post property to Comment?

  • 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-22T21:11:56+00:00Added an answer on May 22, 2026 at 9:11 pm

    Comment should have “PostId”, if it doesn’t it is impossible to define the post for the comment (for example in result sets we have 2 posts and 7 comments)

    So you should add either Post property or PostId to the Comment class.

    Also for simple cases please see the RelationAttribute, the example is here
    See Test2(), this helps to avoid manually relations prepare, no need to write:

    sets[0].AddRelation(sets[1], "PostID", "PostID", "Comments");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following one-to-many relation between two objects. Parent --> IList<Child> Now, I
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
Lets say I have two tables - child and parent with many-to-one relation. What
I have a one to many relationship between two tables. The many table contains
I am learning django admin, i have to models with a one-to-many relation between
I have a question about One-To-Many relationship between two tables when there is the
In my DB I have two relation between two tables : A many to
I have a many to many relation between users and projects: User class: @ManyToMany
I have two one-to-one relations here between a class called MailAccount and the classes
I have one to many relation between folders and docs tabels. I want 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.