title: Can't update related table on sql database, my update code runs with no errors but no changes are made to the foreign table
body: <p>I have two entities and 2 matching tables on SQL local database. User and address, I am trying to update users address information but nothing happens when I run the code, no errors but no data is saved on address table either.</p>
  <pre class="lang-cs prettyprint-override"><code>namespace Entities.Concrete
  {
      public class User : IEntity
      {
          public int Id { get; set; }
          [Required(ErrorMessage = &quot;Username Required&quot;)]
          public string Username { get; set; }
          [Required(ErrorMessage = &quot;Email Required&quot;)]
          [DataType(DataType.EmailAddress)]
          public string Email { get; set; }
          [Required(ErrorMessage = &quot;Password Required&quot;)]
          public string Password { get; set; }
          public int Role { get; set; }
          public virtual Address Address { get; set; }
      }
  }
  
  namespace Entities.Concrete
  {
      public class Address : IEntity
      {
          [ForeignKey(&quot;User&quot;)]
          [Key]
          public int UserID { get; set; }
          public string Country { get; set; }
          public string City { get; set; }
          public string DetailedAddress { get; set; }
          public virtual User User { get; set; }
      }
  }
  public class EfUserDal : EfEntityRepositoryBase&lt;User,InternshipAppContext&gt;, IUserDal
  {
      public void UpdateAddress(User user)
      {
          using (InternshipAppContext context = new InternshipAppContext())
          {
              context.Users.Attach(user);
              context.Entry(user).Reference(u =&gt; u.Address).IsModified = true;
              context.SaveChanges();
          }
      }
  }
  </code></pre>
  <p>The DB diagram:</p>
  <p><a href="https://i.stack.imgur.com/7T4go.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7T4go.png" alt="DB diagram" /></a></p>