Collections in Entity Framework

I may not be the most experience developer, but in my opinion entity framework models should be mapped 1:1 to database tables in order to keep things as simple as possible.

In a database you can represent lists with relationship
So in my opinion, if you have e.g. a table "football team" and a table "player", with the proper references, you should have a FootballTeam.cs class and a Player.css class representing the two entities, containing no collection. Then you could have a third class FootballTeamData.cs including
  • a FootballTeam field
  • a Collection<Player> field
When you retrive the collection of players from Player table by means of GetRange, you can assign it to your FootballTeamData object.

That's my opinoin, let's wait to hear more of them.
Was this page helpful?