title: delete of entities in domain driven design
body: <p>I started to explore the concepts of domain driven design recently. Most examples and explainations I find do assume there is a kind of ORM tool being used to persist the entities in the repository.</p>
  
  <p>At this moment, I am leaning towards the use of Entity Framework as the ORM tool, however some issues come to my mind which might als be applicable with other tools. For example, assume there is a root aggregate Order with multiple OrderLine entities as child:</p>
  
  <ul>
  <li>Order has a readonly collection property exposing the OrderLines</li>
  <li>add and delete of orderlines is implemented by specific methods on the order</li>
  <li><p>when adding or deleting orderlines, the total price of the order needs to be changed accordingly</p>
  
  <ol>
  <li><p>What is the preferred way to detect additions of new OrderLines when saving the Order? In the repository I could check for the value of the id to detect if an line needs to be added or updated. Is this the proper way to do this?</p></li>
  <li><p>How does the order repository detect deletions of lines?</p></li>
  <li><p>How do you restore an entity from the database when some properties are only private settable?</p></li>
  </ol></li>
  </ul>
  
  <p>These examples are easy to implement when exposing a public modifyable collection on the root aggregate, but that makes it possible to modify the collection without using the dedicated methods. Same is true for the restoration with private properties: make them public settable.</p>
  
  <p>And what if I do not want to use an ORM tool, but direct SQL queries, how would the issues be addressed best in that case? Ideally, the domain model would not require modifications in that case, because the way how the changes are persisted is an implementation detail of the repository, so this coult be either EF, NHibernate or plain old SQL.</p>