1

I am trying to get my head around where the aggregates roots lie in my entity framework data model so I know what repositories I need to create.

If I talk in relational database terms for a second, I have an ExceptionGroup object and an Exception object (not system.exception!). An Exception belongs to an ExceptionGroup and cannot exist without an ExceptionGroup.

Should I have a repository for each object or a single repository containing methods for both? If I was to have a single repository the methods would be as follows...

FindAllExceptionsByExceptionGroup(int GroupID)
AddExceptionGroup(ExceptionGroup ExceptionGroup) - because an exception cannot exist without a group.
AddException(DataAccess.Exception Exception)
DeleteExceptionGroupByID(int GroupID)
DeleteExceptionByID(int ExceptionID)
DeleteExceptionByGroup(int GroupID)
Jehof
  • 34,674
  • 10
  • 123
  • 155
Adrian S
  • 1,007
  • 4
  • 12
  • 26

1 Answers1

2

If I understand your model correctly, it sounds like you would have a repository for ExceptionGroup and the ExceptionGroup object would encapsulate access and operations on Exception instances (for ex., by exposing a collection of them). In this way, the forced relationship between the two classes becomes very apparent.

Jeff Sternal has an excellent answer to a similar question here: What's an Aggregate Root? His example of Order / LineItem seems analogous.

Community
  • 1
  • 1
Michael Petito
  • 12,891
  • 4
  • 40
  • 54