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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:42:23+00:00 2026-05-11T16:42:23+00:00

I have a Question object thats the root of the Question Aggregate. THe question

  • 0

I have a Question object thats the root of the Question Aggregate. THe question has associated Answer Entities in its aggregate . When a new Answer object is created, the changes will be saved to DB via repository. Can I call a repository method SaveAnswer(Question ID) or must I call a SaveQuestion(QUestionID) and have the Repository determine what changes were made? If the latter, how is this implemented?

Conversely, If I want to load up all the Answers to a particular Question, must I call GetQuestion() and then pull the answers, or can I simply call GetAnswers(questionID).

tia

  • 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-11T16:42:23+00:00Added an answer on May 11, 2026 at 4:42 pm

    Firstly, let me say there are no hard and fast rules here, this is my understanding of DDD and repository access, but it’s a fairly subjective area…

    So, from a DDD perspective what you might want to do when adding an Answer to an existing Question is something like the following C# style pseudocode:

    using(unitOfWork = new UnitOfWork())
    {
      var question = _questionRepository.GetQuestion(questionId);
      question.AddAnswer(new Answer("blah"));
      unitOfWork.SaveChanges();
    }
    

    Assuming you are using an ORM that handles change tracking and that is configured to cascade child objects back to the database that is all you would need to do (I’m thinking of NHibernate here, but other ORMs can work in a similar way). By adding the Answer to the Question you have told the ORM that you want the Answer to be persisted in the database when the unit of work completes. You typically wouldn’t call SaveAnswer(QuestionId) – that’s not a very DDD-centric way of approaching things where Answer is in the same aggregate as Question and Question is the aggregate root.

    For getting the objects out of the database, typically you would ask the repository for a question object (by id presumably), and then navigate to the Answer from there (via an Answers collection on the Question) – e.g.

    var question = _questionRepository.GetQuestion(questionId);
    foreach(var answer in question.Answers)
    {
      Console.WriteLine(answer.Description); // or do something useful instead!
    }    
    

    If this seems like a strange way to save or retrieve the Answer object then you might want to re-assess whether Answer does actually belong in the same aggregate, or whether it would be better to break it out of the question aggregate altogether.

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

Sidebar

Ask A Question

Stats

  • Questions 234k
  • Answers 234k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems that the community has pulled back from Ferret… May 13, 2026 at 6:04 am
  • Editorial Team
    Editorial Team added an answer Smarty or any template system is another layer of complexity.… May 13, 2026 at 6:04 am
  • Editorial Team
    Editorial Team added an answer Plain (info `file-name') opens file in info mode. (info) probably… May 13, 2026 at 6:04 am

Related Questions

Disclaimer: the following is a sin against XML. That's why I'm trying to change
We're writing an application that's in landscape mode exclusively. We use a transform on
I have a userControl I'm doing some Painting to, and when the control is
I have a pretty sizeable object graph that I have serialized to a file

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.