This problem is similar to:
Code First Multiple Foreign Keys for One to Many Relation
and
Entity Framework Code First - two Foreign Keys from same table
But not similar enough for me to gleen a solution.
I have a model "Team" that has one foreign key to another model called "Room" and a team can only have one room. The room model has two lists of Teams "p2teams" and "p3teams". In the teams table it is actually creating three different id columns to rooms: "RoomID", "Room_RoomID", and "Room_RoomID1".
This result in me trying to set a team's room (such as exampleTeam.Room = exampleRoom) and it only affects the RoomID column and not the rest. Furthermore, I just really don't fully get what is going on to have this result.
Below are my models, DB diagram, and some sample data from the team's table. Thanks for the help!
Team Model:
public class Team
{
public int TeamID { get; set; }
public int HighschoolID { get; set; }
public virtual Highschool Highschool { get; set; }
public int ContestID { get; set; }
public virtual Contest Contest { get; set; }
[ForeignKey("Room")]
public int? RoomID { get; set; }
public virtual Room Room { get; set; }
public string Warning { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
Room Model:
public class Room
{
public int RoomID { get; set; }
public virtual ICollection<RoomUsage> RoomUsages { get; set; }
public string Name { get; set; }
public int? AvailibleSeats { get; set; }
public int? TotalSeats { get; set; }
public virtual ICollection<Student> p1Students { get; set; }
public virtual ICollection<Team> p2Teams { get; set; }
public virtual ICollection<Team> p3Teams { get; set; }
}
Once again, thanks for all your help.