title: EF One-to-One Update fails
body: <p>I have one-to-one relationship defined in EF6 which works for Inserts. Unfortunately when I try an update with a disconnected record, I receive an error. Here are details:</p>
  
  <p><strong>.NET Source:</strong></p>
  
  <pre><code>namespace EF_ConsoleApp_Test
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              int? accountId;
              int? customerId;
  
              using (var db = new MainContext())
              {
                  var account = new Account
                  {
                      AccountNumber = "1234",
                      Customer = new Customer {FirstName = "John"}
                  };
  
                  db.Accounts.Add(account);
                  db.SaveChanges();
  
                  accountId = account.Id;
                  customerId = account.Customer.Id;
              }
  
              using (var db = new MainContext())
              {
                  // disconnected record
                  var account = new Account()
                  {
                      Id = accountId,
                      AccountNumber = "9876",
                      Customer = new Customer() {Id = customerId}
                  };
  
                  db.Accounts.Add(account);
                  db.Entry(account).State = EntityState.Modified;
                  db.Entry(account.Customer).State = EntityState.Unchanged;
  
                  db.SaveChanges(); // Error occurs here
              }
          }
  
          [Serializable]
          [Table("CUSTOMERS")]
          public class Customer
          {
              [Key] [Column("CUSTOMER_ID")] public int? Id { get; set; }
  
              [Required]
              [Column("FIRST_NAME")]
              [StringLength(45)]
              public string FirstName { get; set; }
  
              public virtual Account Account { get; set; }
  
              public Customer() { }
          }
  
          [Serializable]
          [Table("ACCOUNTS")]
          public class Account
          {
              [Key]
              [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
              [Column("ACCOUNT_ID")]
              public int? Id { get; set; }
  
              [Required]
              [Column("ACCOUNT_NUMBER")]
              [Display(Name = "Account Number")]
              [StringLength(16)]
              public string AccountNumber { get; set; }
  
              public virtual Customer Customer { get; set; }
  
              /// &lt;summary&gt;
              /// Default Constructor
              /// &lt;/summary&gt;
              public Account() { }
          }
  
          internal class MainContext : DbContext
          {
              internal MainContext() : base("name=ACHRE.Context")
              {
                  Database.SetInitializer&lt;MainContext&gt;(null);
              }
  
              public virtual DbSet&lt;Account&gt; Accounts { get; set; }
  
              public virtual DbSet&lt;Customer&gt; Customers { get; set; }
  
              protected override void OnModelCreating(DbModelBuilder modelBuilder)
              {
                  // Configure FK
                  modelBuilder.Entity&lt;Customer&gt;()
                      .HasRequired(c =&gt; c.Account)
                      .WithRequiredPrincipal(a =&gt; a.Customer)
                      .Map(m =&gt; m.MapKey("CUSTOMER_ID"));
  
                  base.OnModelCreating(modelBuilder);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Database Table Create statements:</strong></p>
  
  <pre><code>CREATE TABLE [dbo].[CUSTOMERS](
      [CUSTOMER_ID] [INT] IDENTITY(1,1) NOT NULL,
      [FIRST_NAME] [varchar](45) NOT NULL,
   CONSTRAINT [PK_CUSTOMERS] PRIMARY KEY CLUSTERED 
  (
      [CUSTOMER_ID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  CREATE TABLE [dbo].[ACCOUNTS](
      [ACCOUNT_ID] [INT] IDENTITY(1,1) NOT NULL,
      [CUSTOMER_ID] [int] NOT NULL,
      [ACCOUNT_NUMBER] [varchar](16) NOT NULL,
   CONSTRAINT [PK_ACCOUNTS] PRIMARY KEY CLUSTERED 
  (
      [ACCOUNT_ID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  ALTER TABLE [dbo].[ACCOUNTS]  WITH CHECK ADD  CONSTRAINT [FK_ACCOUNTS_CUSTOMERS] FOREIGN KEY([CUSTOMER_ID])
  REFERENCES [dbo].[CUSTOMERS] ([CUSTOMER_ID])
  GO
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>A relationship from the 'Customer_Account' AssociationSet is in the
    'Added' state. Given multiplicity constraints, a corresponding
    'Customer_Account_Target' must also in the 'Added' state.</p>
  </blockquote>
  
  <p>What do I need to update to make this work?</p>
  
  <p><strong>Notes</strong> </p>
  
  <ul>
  <li>This related to <a href="https://stackoverflow.com/questions/50011305/entity-framework-one-to-one-referentialconstraint-is-mapped-to-a-store-gener">question</a> I asked before that was related to Inserts. The Insert was resolved but introduced this issue when the Foreign Keys were removed.</li>
  <li>Using EF 6.2 and .NET 4.7.1.</li>
  </ul>