0

As I understand from Evans book, aggregate root are entities that are uniquely identifiable in a domain.

Now, I am modelling an aggregate root which can be uniquely identified by a string that is composed of three of it's attributes - "ProjectCode-Date-CollectionId".

Can I use this string as an identity key for my aggregate root or should I be using surrogate keys?

If I use surrogate keys, then every time a new entry is to be added to the database, I would have to query the table to see if a combination of these three attributes already exist. Is this OK?

user2822838
  • 337
  • 1
  • 3
  • 13
  • 1
    I would avoid using this pseudo-key, as it is meaningless in the domain. The correct approach would be to enforce uniqueness in the domain, it possible to enforce via mechanism other than querying the table (unique constraints, etc.- but that is more of an implementation detail). – pragmatical May 20 '14 at 13:52

1 Answers1

0

Don't put any logic into the identifier of the aggregate root, and - as pragmatical suggests - the uniqueness of the ProjectCode-Date-CollectionId combination sounds like a rule in the domain. It may be implemented in various ways, as a domain servcie perhaps.

oakman
  • 297
  • 1
  • 8