title: C# .NET 4.5 and EF 5 update navigation property (foreign key)
body: <p>I can't update navigation property
  I have two entities: User</p>
  
  <pre><code>public class User : Entity
  {
      public string Username { get; set; }
      public string Password { get; set; }
  
      public int? AddressId { get; set; }
      public virtual Address Address { get; set; }
  }
  </code></pre>
  
  <p>And Address</p>
  
  <pre><code>public class Address : Entity
  {
      public string AddressName { get; set; }
  
      public int UserId { get; set; }
      public virtual User User { get; set; }
  
  }
  </code></pre>
  
  <p>When i am trying to do following:</p>
  
  <pre><code>address.User = user;
  </code></pre>
  
  <p>address userId updates succesfully, and in commit method, entity state is Modified.
  But users AddressId won't update.</p>
  
  <p>Here is my context</p>
  
  <pre><code>public DbSet&lt;User&gt; Users { get; set; }
  public DbSet&lt;Address&gt;  Addresses { get; set; }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;User&gt;()
                      .HasOptional(x=&gt;x.Address)
                      .WithMany()
                      .HasForeignKey(x=&gt;x.AddressId)
                      .WillCascadeOnDelete(false);
      base.OnModelCreating(modelBuilder);
  }
  </code></pre>
  
  <p>And i am using unity framework and genereic repository pattern.
  I tried to set all properties to virtual but no effect.</p>