I get this error when writing to the database:
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: \'Paym
My problem was caused by redundant defining of the Primary key in the configuration.
this
.Property(p => p.Id)
.HasColumnName(@"id")
.IsRequired()
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity) // this is redundant when you want to configure a One-to-Zero-or-One relationship
.HasColumnType("int");
Remove this line
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
Example http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx
This is enough to define the relationship
// Configure Student & StudentAddress entity
modelBuilder.Entity()
.HasOptional(s => s.Address) // Mark Address property optional in Student entity
.WithRequired(ad => ad.Student); // mark Student property as required in StudentAddress entity. Cannot save StudentAddress without Student