I'm not a DDD expert, but as far as I know you have two options: 1. Retrieve the Post from your PostRepository, then iterate over the Comments to find the correct comment, update it, then save the Post to cascade the comment change to the database. 2. Use a CommentRepository to retrieve the correct comment, update it, then save it.
Option #2 is obviously more performant, and really more intuitive. However, it does violate the "only have repositories for aggregate root" DDD rule. They aren't a silver bullet and forcing your code to abide by them when a more logical and performant solution exists might be missing the forest for the trees. Kevin On Jan 28, 2:57 pm, "Paul Hinett" <[email protected]> wrote: > Hi, > > I am trying to setup my domain using strict DDD rules, one of them is > aggregate roots...how am i supposed to select and update a single item from > a collection of objects inside my aggregate root? > > For example say i have a post which is the aggregate root, which has lots of > comments and i wanted to edit a single comment. How can i get this post from > the collection, make some changes to it then persist it again? > > Without using aggregate root i could setup a repository for the comments, > select one and update it quite easily, but as far as i understand when using > aggregate roots you shouldn't need a repository for the comments. > > I am using S#arp arch if that makes any difference. > > Thank You, > > Paul -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
