title: FK Violation using EF Upsert logic with internal object retrieved from DB
body: <p>so I am implementing EF in my project. In my unit testing I have come accross an issue I cannot seem to figure out on my own... </p>
  
  <p>I have... </p>
  
  <pre><code>class Employee{
     Guid uid
  name: "Foo";
  Department: dempartmentObj;
  }
  
  class department{
      Guid uid
  name: "food prep";
  desc: "preps food";
  }
  </code></pre>
  
  <p>now as part of the logic from the program I am creating a new employee and linking them into the new department </p>
  
  <p>so I </p>
  
  <pre><code>var x = new employee();
   x.department = context.get(uid); //ef context call to retrieve a department
  </code></pre>
  
  <p>then use upsert logic to save int he event the code is used to modify instead of add</p>
  
  <pre><code>context.Entry(x).state = x.uid == guid.empty ?
        EntityState.Added: EntityState.Modified;
  
  if(x.uid == Guid.Empty)
            x.uid = Guid.newGuid();
  
  context.SaveChanges();
  </code></pre>
  
  <p>with unit testing I have confirmed that it works when Creating both new employee and department </p>
  
  <p>however when retrieving the innner object I run into primary key violations trying to save the new employee...</p>