Apparently you want to have a one-to-one relationship between Fixture
and Result
(a Result
entity cannot be shared between multiple Fixture
s), right? In this case your mapping is not 100% correct. You need:
modelBuilder.Entity<Fixture>()
.HasOptional(f => f.Result)
.WithRequired();
If you don't add WithRequired
EF conventions will assume a WithMany
, i.e. a one-to-many instead of one-to-one relationship.
Speaking of conventions, you can actually remove modelBuilder.Entity<Gameweek>().HasMany(g => g.Fixtures);
, all [Required]
attributes and the [Key]
attribute in Gameweek
. Only the one-to-one mapping above and the [Key]
attribute on Result.FixtureID
is needed. Everything else will be mapped automatically based on conventions.