DDD entity and database representation

domain-driven-design

I m studying DDD in a development context, and it seems that I've misunderstood something.

Actually, I was thinking that an Entity is the object that can be persisted on a storage support like a database.

But does it mean that the entity is the same thing than a row in my database ?

I mean there, can it exist objects between my Entities and my database, like a representation of a database row, that will be "converted" to my business entity ?

Best Answer

But does it mean that the entity is the same thing than a row in my database ?

No, absolutely not. Your database might not even be a database; remember that a REPOSITORY provides "the illusion of an in-memory collection of all objects of that type" (Evans, chapter 6). It can, of course, support this illusion by in fact being an in-memory collection of objects.

I mean there, can it exist objects between my Entities and my database, like a representation of a database row, that will be "converted" to my business entity ?

Yes. For instance, in event-sourcing, "rows" in the database are representations of "events", each of which describes a change of the state of an entity. In such a system, you load the entity by reading from the the database a representation of the history of the entity, and then "replay" that history to get a representation of the entity itself.