title: Struggling with DDD, Repository Pattern, and Associated Domain Models
body: <p>I'm really struggling to wrap my head around some of this stuff. Let me give an example of where I'm struggling.</p>
  
  <p>I'm using Linq-2-Sql as the DAL for my app and the IRepository pattern used in the MVC Storefront sample app from Rob Conery.</p>
  
  <p>In my domain I have a Customer Model which has a collection of Address Models. In my UI there is a button which allows the user to add a new address to the customer. This opens up an address editor which let's them fill in all the information.</p>
  
  <p>What happens next? Does the address get saved to the database, then added to the list in my customer object? Does it just get added to the list but not updated until the Customer object get's saved? What if the user wants to delete an address? Do I delete the address in the database and then remove it from the list? Or do they just make all the deletes/adds they want and I dump everything from the database everytime and update it with whatever is in the Customer.Addresses collection? What's the right flow here?</p>
  
  <p>Should the collection of addresses only get updated via the Repository by calling something like this:</p>
  
  <pre><code>public void AddAddressToCustomer(Customer c, Address a)
  {
      //validate and save address to db
      //add the newly saved address to the Customer Object
  }
  </code></pre>
  
  <p>Help...</p>