title: Update of navigation property in EF7 does not get saved
body: <p>I have simple model:</p>
  
  <pre><code>public class Post
  {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public long Id { set; get; }
          //non-important properties stripped, to focus on problem
          public virtual Resource Resource { set; get; }
  
          public virtual ICollection&lt;Tag&gt; Tags { set; get; }
  }
  public class Resource
  {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public Guid Id { set; get; }
  
          [Url]
          public string Url { set; get; }
  }
  </code></pre>
  
  <p>and DbContext (I use ASP.NET identity in this project, if this is relevant):</p>
  
  <pre><code>public class DbContext : IdentityDbContext&lt;User&gt;
  {
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
              base.OnModelCreating(modelBuilder);
              var postEntity = modelBuilder.Entity&lt;Post&gt;();
              postEntity.Reference(p =&gt; p.Resource).InverseCollection(); //no navigation property on Resource side
              postEntity.Collection(p =&gt; p.Tags).InverseReference(tag =&gt; tag.Post);
              postEntity.ToTable("Posts");
  
              var resourceEntity = modelBuilder.Entity&lt;Resource&gt;();
              resourceEntity.ToTable("Resources");
  
              var tagEntity = modelBuilder.Entity&lt;Tag&gt;();
              tagEntity.Reference(t =&gt; t.Post).InverseCollection(p =&gt; p.Tags).Required(false);
              tagEntity.ToTable("Tags");
         }
  }
  </code></pre>
  
  <p>After migration (SQL Server), database tables looks like expected - Post table has Foreign Key to ResourceId.</p>
  
  <p>Creating Post's works fine, when I attach post.Resource (already created Resource).</p>
  
  <p><strong>My problem occurs when I want to replace post.Resource</strong>.
  <strong>By replace, I mean selecting one of already existing Resources and assigning it to post.</strong></p>
  
  <p><code>var resource2 = Database.Resources.First(r=&gt;r.Url == "xyz");</code></p>
  
  <p>I have tried:</p>
  
  <ol>
  <li><p><code>post.Resource = resource2; Database.Entry(post).State = EntityState.Modified;</code></p></li>
  <li><p><code>Database.Entry(post).Property(p =&gt; p.Resource).CurrentValue = resource2;</code></p></li>
  <li><p><code>post.Resource = null;</code></p></li>
  </ol>
  
  <p><strong>With different combinations of them also</strong>, but none of them works. After calling <code>await SaveChangesAsync();</code> and looking up in database - there are no changes. How to perform the replace (update of foreign key) properly?</p>
  
  <p>//Update 14.09.2015
  <em>Issue was caused by additional select, performed to update One-To-Many relationship.</em> Full code:</p>
  
  <pre><code>        var Database new DbContext();
          var resource2 = Database.Resources.First(r=&gt;r.Url == "xyz");
          var oldAssignedTags = Database.Posts.Include(p=&gt;p.Tags).FirstOrDefault(p =&gt; p.Id == post.Id).Tags;
          var tags = newTags as List&lt;Tag&gt; ?? newTags.ToList();
          //TagComparer is irrelevant here
          var toRemove = oldAssignedTags.Except(tags, TagComparer);
          var toAdd = tags.Except(oldAssignedTags, TagComparer);
  
          foreach (var tag in toRemove)
          {
              Database.Entry(tag).State = EntityState.Deleted; //Database.Tags.Remove(tag);
          }
  
          foreach (var tag in toAdd)
          {
              tag.Post = post;
              post.Tags.Add(tag);
          }
  
          post.Resource = resource2;
          await Database.SaveChangesAsync();
  </code></pre>