title: Entity Framework 6 A dependent property in a ReferentialConstraint is mapped to a store-generated column. Error
body: <p>I have 2 entities configured using Entity Framework 6. 
  Both entities have Identity on for generating primary keys on insert. </p>
  
  <p>When i try adding new customer I get following error. 
  <code>
  A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'Id'.
  </code></p>
  
  <p>My assumption is that I did not configured one of the entities properly for one to one relationships.</p>
  
  <pre><code>public class Customer : IdEntity
      {
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public Guid? BalanceId { get; set; }
          public DateTime? Dob { get; set; }
          public DateTime CreateDate { get; set; }
  
          public CustomerBalance Balance { get; set; }
          public Address Address { get; set; }
  
          public virtual ICollection&lt;Email&gt; Emails { get; set; } = new List&lt;Email&gt;();
          public virtual ICollection&lt;Phone&gt; Phones { get; set; } = new List&lt;Phone&gt;();
          public virtual ICollection&lt;Reward&gt; Rewards { get; set; }
          public ICollection&lt;Call&gt; Calls { get; set; }
      }
  </code></pre>
  
  <p>Here is mapping for Customer </p>
  
  <pre><code>public class CustomerConfiguration : EntityTypeConfiguration&lt;Customer&gt;
      {
          public CustomerConfiguration()
          {
              ToTable(nameof(Customer));
              HasKey(x =&gt; x.Id).Property(x =&gt; x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
              HasMany(x =&gt; x.Phones);
              HasMany(x =&gt; x.Emails);
              HasOptional(x =&gt; x.Balance);
   HasRequired(x =&gt; x.Address).WithRequiredDependent(x=&gt;x.Customer);
          }
  
      }
  </code></pre>
  
  <p>Here is Address Entity</p>
  
  <pre><code>public class Address : IdEntity
      {
          public string Address1 { get; set; }
          public string Address2 { get; set; }
          public string City { get; set; }
          public string State { get; set; }
          public string Zip { get; set; }
          public string Country { get; set; }
          public int CustomerId { get; set; }
  
          public virtual Customer Customer { get; set; }
      }
  </code></pre>
  
  <p>And mapping</p>
  
  <pre><code> public class AddressConfiguration : EntityTypeConfiguration&lt;Address&gt;
      {
          public AddressConfiguration()
          {
              ToTable(nameof(Address));
              HasKey(x =&gt; x.Id, e =&gt; e.IsClustered())
                  .Property(x =&gt; x.Id)
                  .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
  
          }
      }
  </code></pre>
  
  <p>Here is a code how i insert new customer </p>
  
  <pre><code> var customer = new Customer
              {
                  FirstName = request.FirstName,
                  LastName = request.LastName,
                  CreateDate = DateTime.Now,
                  Address = new Address()
              };
              if (!string.IsNullOrEmpty(request.Email))
                  customer.Emails.Add(new Email { EmailName = request.Email, IsPrimary = true });
              if (!string.IsNullOrEmpty(request.Phone))
                  customer.Phones.Add(new Phone { Number = request.Phone, IsPrimary = true });
  
              _repository.AddOneAsync(customer);
              await _repository.Context.SaveChangesAsync();
  
  </code></pre>
  
  <p>Error is happening on save changes.
  Address and Customer are one to one relationship.  </p>
  
  <p>Here is how my tables are configured at SQL </p>
  
  <p><a href="https://ibb.co/cYYphbJ" rel="nofollow noreferrer">https://ibb.co/cYYphbJ</a></p>
  
  <p><a href="https://ibb.co/LnXcsyB" rel="nofollow noreferrer">https://ibb.co/LnXcsyB</a></p>