I am trying to create game where I use a restful server to control multiplayer games
The game is a board game with 2 players, but I am in doubt how to create my database so it makes sense
One player will have a foreign key to a gameID but another player will as well (Player 1 and Player 2)
So if my game model has something like
public virtual GameId {get;set;}
......
public virtual Player1Id {get;set;}
public virtual Player2Id {get;set;}
Then how am I supposed to create the database when a PlayerId can be both at the Player1 and Player2 spot in the game model? The FK cant link to a certain spot everytime and thats my worry
Ps I my database experience is rather limited
You wouldn’t need a PlayerId on your game object. The player object needs a GameId to reference it.
This creates a one-to-many relationship. Each game has many players. Although in reality in your situation you are describing only having two players for one game.
The other alternative would be to have PlayerOneId and PlayerTwoId as foreign keys, therefore creating two one-to-one relationships.