I am wondering about what's considered the better or more correct practise in the following scenario:
I've mapped the following business entities with NHibernate:
A Wall has zero-to-many WallPosts. A WallPost has zero-to-many WallPostComments. The aggregate root is Wall.
I'm writing a task to add a WallPostComment to a WallPost. The application is an MVC application, and the request to add the new WallPostComment contains the id of the WallPost to which the comment belongs. In order to add the comment I need to retrieve the post that it should be added to. My question is: what's the best/most correct way of doing this?
I've tried two approaches so far and one feels more 'correct', though it's inefficient. Another, more efficient, approach feels a 'wrong.'
1) I load the Wall aggregate root from the session and select FirstOrDefault from its Posts collection. This feels 'correct' in that I'm accessing the wall post via the aggregate root, but doing this results in all wall posts being fetched from the database (unbounded result set).
2) I load the wall post directly from the session using the wallPostId passed to me by the request. This feels 'wrong' because I'm going around the aggregate root - but it's a single hit on the database for a single row of data.
Which is the better or preferred approach? What other suggestions do you have?
Is there really a Wall? What is the relationship between a Wall and other actors in your domain? I would guess that a Wall is connected with a user and that a user has a single wall. Is that correct? In which case a wall is simply a collection of WallPosts and related comments. In which case your WallPost is your aggregate root and there is no Wall at all.