I want to delete a table row that is split on two entities.
If I try to delete the main entity, I get an error if before I don\'t load the related other entity using
Replace your override method with this code and check
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity() // one-to-one
.ToTable("Products")
.HasKey(e => e.Id)
.HasRequired(e => e.Info)
.WithRequiredDependent(e => e.Product);
modelBuilder.Entity() // map to the same table Products
.ToTable("Products")
.HasKey(e => e.Id);
//add this code
modelBuilder.Entity()
.HasRequired(p => p.Photo) // "Photo" defined in Product class for ProductPhoto class's object name
.WithRequiredPrincipal(c => c.Product);// "Product" defined in ProductPhoto class for Product's class object name
base.OnModelCreating(modelBuilder);
}