Logically, you are trying to define a 1-to-many relationship. Because City
cannot be in many Provinces
, and one Province
can have many Cities
.
In this case, you don't necessarily need to specify HasRequired
and WithMany
in your mapping.
Remove the following code from CityMap
this.HasRequired(x => x.Province)
.WithMany(x => x.Cities)
.HasForeignKey(x => x.Id);
Having ICollection<City>
in Province
table, and a property type of Province
in City
table is enough to establish the relationship.
The output will be like this.