When I design documents I usually use link documents to define relations between different document types.
Something like:
EmailDocument
- Id
- Subject
- UserLink
- DisplayName
- UserId
User
- Id
- FirstName
- LastName
The problem is if a user changes it’s name, the old name are left in all related documents. Is the link documents a bad approach or are there an easy way to update all those links? (I usually create a class called User and one called UserLink. UserLink is included in all other documents that has a relation to a user.)
No, I don’t think it’s a bad approach, since it will improve performance in many cases. But it does add complexity and require you to have a strategy for updating the name when the parent entity changes (User).
A common design around this is to expose events – when the event “UserChangedName” is raised, you can have a listener that updates all DisplayName’s in all EmailDocument instances.