I'm trying to learn how to use Entity Framework to create my database. My data has a many-to-many relationship in it. To simplify, think of it as wanting to store the Lineups for every baseball game this year.
I have a Game class that holds specifics about the game (date, which teams, location, etc.). I have a Player
class that holds specifics about each player. I then have a Lineup
class that I expect to be a many-to-many join of these two tables.
The table I'm expecting (Lineup) would look like this:
GameId int
PlayerId int
I'm not seeing how to get that to happen. Either I get a table that has GameId as PK and PlayerId as FK, or if I use the [Key]
attribute, I get told there's no key set on the class.
Any thoughts on how to approach this? Or, is my only option really to create the DB first, then use EF to create the models?