title: DDD - Repository Pattern returning db keys?
body: <p>There is a big design flaw here, but I'm having trouble solving it:</p>
  
  <p>The business need is a little involved so I'll try to keep this simple.
  We have a table with purchases, and a table for returns. When a return is made, we have to find match that return to the oldest purchase in the db, and record that in a "returns applied" table.</p>
  
  <p>So, when I insert a Return, within that transaction, I need to apply the return to a purchase record.</p>
  
  <p>As it stands now, we have a service that calls the repository for the insert. The service needs to know what the key is of that inserted record, so that it can finish the transaction by inserting an "applied" record using that key.</p>
  
  <p>We're basically stuck because my understanding is that a repository should not return this kind of data. Doesn't this defeat the idea of the Repository being a collection?</p>
  
  <p>What is the alternative?</p>
  
  <p><strong>CLARIFICATION:</strong></p>
  
  <p>We have a Purchase table, a Return table, and an Applied table</p>
  
  <p>The applied table looks like this
  purchaseId     returnId   qtyReturned</p>
  
  <p>So when a return is <em>inserted</em> I need the id of a purchase (decided by some business rules) and the id of the newly inserted return.</p>