I do not understand how DDD works with an ORM
Posted: Wed Feb 05, 2014 5:35 pm
Hello everyone!
So I'm trying to piece together how domain driven design (DDD) concepts can work in harmony (if at all) with an ORM layer. I understand that the domain layer is meant to be persistent ignorant (has no knowledge of persistence) and domain focused (via some ubiquitous, domain language).
Then we have an ORM layer, which is (meant) to be a one to one mapping between records in a table and an object. So, if a table has three fields (id, name, email) then so does the class. If, say, we instantiate this class and call it A, then performing A.save() will persist these three object fields into the corresponding record in the table, via the primary key (id).
The problem is, where does DDD come into this? If we have this class A, it surely cannot be in the domain layer, as it's too close to persistence. What's even worse is that A.save() persists the class, while DDD dictates that a repository P save the class via P.Save(A); persistence is too close to the domain.
Do I put domain level logic into A?
So I'm trying to piece together how domain driven design (DDD) concepts can work in harmony (if at all) with an ORM layer. I understand that the domain layer is meant to be persistent ignorant (has no knowledge of persistence) and domain focused (via some ubiquitous, domain language).
Then we have an ORM layer, which is (meant) to be a one to one mapping between records in a table and an object. So, if a table has three fields (id, name, email) then so does the class. If, say, we instantiate this class and call it A, then performing A.save() will persist these three object fields into the corresponding record in the table, via the primary key (id).
The problem is, where does DDD come into this? If we have this class A, it surely cannot be in the domain layer, as it's too close to persistence. What's even worse is that A.save() persists the class, while DDD dictates that a repository P save the class via P.Save(A); persistence is too close to the domain.
Do I put domain level logic into A?