title: Updating complex type with ef code first
body: <p>I have a complex type called account, which contains a list of licenses.
  Licenses in turn contains a list of domains (a domain is a simple id + url string).</p>
  
  <p>In my repository I have this code</p>
  
  <pre><code>    public void SaveLicense(int accountId, License item)
      {
  
          Account account = GetById(accountId);
          if (account == null)
          {
              return;
          }
  
  
          if (item.Id == 0)
          {
              account.Licenses.Add(item);
          }
          else
          {
              ActiveContext.Entry(item).State = EntityState.Modified;
          }
  
  
          ActiveContext.SaveChanges();
      }
  </code></pre>
  
  <p>When I try to save an updated License (with modified domains) what happens is that strings belonging straight to the license get updated just fine.</p>
  
  <p>However no domains get updated.</p>
  
  <hr>
  
  <p>I should mention that what I have done is allow the user to add and remove domains in the user interface. Any new domains get id=0 and any deleted domains are simply not in the list.</p>
  
  <p>so what I want is</p>
  
  <ol>
  <li>Any domains that are in the list and database and NOT changed - nothing happens</li>
  <li>Any domains that are in the list and database, but changed in the list - database gets updated</li>
  <li>Any domains with id=0 should be inserted (added) into database</li>
  <li>Any domains NOT in the list but that are in the database should be removed</li>
  </ol>
  
  <p>I have played a bit with it with no success but I have a sneaky suspicion that I am doing something wrong in the bigger picture so I would love tips on if I am misunderstanding something design-wise or simply just missed something.</p>