Suppose I have a Team class that contains 0 or more Players .
The Player class is simple:
public class Player { public long Id { get; set; } public string Name { get; set; } public Team Team { get; set; } }
But what is the best way to define a Team class?
Option 1
public class Team { public long Id { get; set; } public string Name { get; set; } public ICollection<Player> Players { get; set; } }
Option 2:
public class Team { public Team() { Players = new Collection<Player>(); } public long Id { get; set; } public string Name { get; set; } public ICollection<Player> Players { get; set; } }
Option 3:
public class Team { public long Id { get; set; } public string Name { get; set; } public IQueryable<Player> Players { get; set; } }
Option 4:
public class Team { public long Id { get; set; } public string Name { get; set; } public ObjectSet<Player> Players { get; set; } }
collections entity-framework iqueryable poco
Stef heyenrath
source share