My use case is pretty much identical to what I see in the tutorials: I have a class Slachtoffer and another class Schadeberekening. Each Schadeberekening must have a Slachtoffer, and a Slachtoffer can have a Schadeberekening.
I am trying to set up the database using code-first like this:
public class Slachtoffer
{
public int Id { get; set; }
public int? SchadeberekeningId{ get; set; }
public Schadeberekening? Schadeberekening { get; set; }
}
public class Schadeberekening
{
public int Id { get; set; }
public int SlachtofferId { get; set; }
public Slachtoffer Slachtoffer { get; set; }
}
modelBuilder.Entity<Slachtoffer>()
.HasOne(s => s.Schadeberekening)
.WithOne(ad => ad.Slachtoffer)
.HasForeignKey<Schadeberekening>(ad => ad.SlachtofferId);
modelBuilder.Entity<Schadeberekening>()
.HasOne<Slachtoffer>(a => a.Slachtoffer)
.WithOne(sa => sa.Schadeberekening)
.HasForeignKey<Slachtoffer>(sa => sa.SchadeberekeningId);
Yet when I look at the created tables, only in the Slachtoffer table, the PK from the Schadeberekening is considered as foreign key. In the Schadeberekening table, it is just an "int".
How can I fix this?



