title: Marking navigation property as modified in Entity Framework 7
body: <p>I have an EF7 <code>DbContext</code> with disabled change tracking because I want to mark all changes explicitly:</p>
  
  <pre><code>var entry = context.Entry(changedEntity);
  entry.Property(propertyName).IsModified = true;
  </code></pre>
  
  <p>This works exactly as I want it to.</p>
  
  <p>However, this does not work when a reference (navigation property) has been updated.</p>
  
  <p>For example, let's say my entity has two properties - <code>ParentId</code> and <code>Parent</code> where <code>ParentId</code> is a foreign key and <code>Parent</code> is the reference to the parent entity.</p>
  
  <p>Calling</p>
  
  <pre><code>entry.Property("Parent").IsModified = true;
  </code></pre>
  
  <p>does not work and throws <code>ModelItemNotFoundException</code> because <code>Parent</code> is not a property of the entity in terms of EF (it is a navigation instead).</p>
  
  <p>In EF6, this could be done as follows:</p>
  
  <pre><code>var reference = context.Entry(changedEntity).Reference("Parent");
  reference.CurrentValue = reference.CurrentValue;
  </code></pre>
  
  <p>IN EF7, there is no such function. I can get to the <code>INavigation</code> object with</p>
  
  <pre><code>entry.Metadata.GetNavigation("Parent")
  </code></pre>
  
  <p>but cannot see any way to mark it as modified.</p>
  
  <p>So, how should I do it?</p>
  
  <p>Note:
  I know that setting <code>ParentId</code> would work, but this is not suitable for me because the referenced entity does not have ID yet as it has just been created and will get its ID from database when saved. Thus, I need to set it through the reference <code>Parent</code>.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The note above was true for EF6 but is no longer valid for EF7 which I was not aware of. Thus, the solution is just as described in the note and answer below.</p>