Ich habe diese zwei Klassen, wo ich eine eins zu viele Beziehung hinzufügen möchte.Eins zu viele Beziehung - Code zuerst
Ein Monster hat nur einen Standort
Aber
Ein Standort viele Monster
haben kann, aber ich bekomme diese Fehlermeldung, wenn ich versuche zu Update-Database
Die ALTEN TABLE-Anweisung in Konflikt mit dem FOREIGN KEY Einschränkung "FK_dbo.Monsters_dbo.Locations_LocationId". Der Konflikt ist in der Datenbank "Idle", Tabelle "dbo.Locations", Spalte "LocationId" aufgetreten.
Monster
public class Monster
{
public Monster()
{
}
public int MonsterId { get; set; }
public string Name { get; set; }
public int Gold { get; set; }
public int Experience { get; set; }
public int Level { get; set; }
public int LocationId { get; set; }
[ForeignKey("LocationId")]
public virtual Location Location { get; set; }
}
Ort
public class Location
{
public Location()
{
Monsters = new List<Monster>();
}
public int LocationId { get; set; }
public string Name { get; set; }
public virtual ICollection<Monster> Monsters { get; set; }
}