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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:33:33+00:00 2026-05-11T08:33:33+00:00

So lets say I have a class called Post that contains an IList I

  • 0

So lets say I have a class called Post that contains an IList

I find that it’s quite easy to cope with adding of Comments to the list when I ask my repository to update my post it can see which comments are new and send down to my data layer the required information, but what about when a comment is deleted? How do you handle this?

Would you pull back a list of comments to check which ones no longer exist in the current changed collection?

Or wire up events to keep track of it?

or something else entirely?

Just for further information, I’m doing this in C# and can’t use a O/R Mapper. I have to use stored procedures to retrieve datasets and map my objects manually. I may have my understanding of the repository pattern wrong, but I am using it to mediate to the data layer, from requesting data, adding data and such, and it maps my dataset data to objects and returns the object(s). So feel free to elaborate on how to use the Repository pattern as well if you wish.

  • 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. 2026-05-11T08:33:34+00:00Added an answer on May 11, 2026 at 8:33 am

    If I understand what you are attempting, you are adding a Comment() to the IList in question which is attached to a Post(). And within your Post(), you are looking for any new Comment()s in the IList and saving them. Having the Post() object control its child objects, such as Comment()s, does go down the road of DDD.

    I am still new to these patterns myself; but personally, I lean towards the concept that any entity that has metadata, I treat as its own entity model; therefore, I create my own repostiory for each entity model.

    Post() PostRepository : IPostRepository  Comment() CommentRepository : ICommentRepository 

    Now, having a IList Post.Comments I believe violates the Law of Demeter by allowing you to execute Post.Comments.Add().

    I believe a solution to your problem would be not add to the IList, but instead create methods on the Post() to handle the comments related to that Post instance:

    Post.AddComment() Post.FetchComments() Post.DeleteComments(IList<Comment> comments)  

    Then within your Post() object, you would wire up your ICommentRepository (most likely with a ServiceLocator, or I prefer Castle Windsor) and handle adding and deletion of them.

    ICommentRepository.AddByPostID() ICommentRepository.FetchByPostID() ICommentRepository.Remove(int commentID) 

    Again, I am still new to the DDD patterns; but, I believe this is keeps the Seperation of Concerns valid and masks the underlying logic by keeping it within the Post()’s concern to ‘only handle actions on comments related to this Post object’.

    The complete Post() class would be something like this:

    private ICommentRepository _commentRepo;  public class Post {   public Post(ICommentRepository commentRepo)   {     // Or you can remove this forced-injection and use a      // 'Service Locator' to wire it up internall.     _commentRepo = commentRepo;   }    public int PostID { get; set; }    public void DeleteComments(IList<Comment> comments)   {     // put your logic here to 'lookup what has been deleted'     // and then call ICommentRepository.Delete() in the loop.      _commentRepo.Remove(commentID);   } } 

    Please comment if others have opinions or changes.

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

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • 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
  • added an answer I rarely write try/catch blocks - most exceptions get thrown… May 11, 2026 at 3:22 pm
  • added an answer You probably want to use CheckBoxList. May 11, 2026 at 3:22 pm
  • added an answer Just convert it to timestamp datetime.datetime.fromtimestamp(ms/1000.0) May 11, 2026 at 3:22 pm

Related Questions

Let's say I have a class called Store that has many Employees. My RESTful
Let's say I have a generic member in a class or method, like so:
Let's say I have a class that implements the IDisposable interface. Something like this:
I am using an api which interacts with a db. This api has methods

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.