How to define a collection in a POCO in Entity Framework 4?

Posted by Stef on Stack Overflow See other posts from Stack Overflow or by Stef
Published on 2010-04-14T10:24:06Z Indexed on 2010/04/14 13:13 UTC
Read the original article Hit count: 296

Lets say I've a Team class which contains 0 or more Players.

The Player class is easy:

public class Player
{
    public long Id { get; set; }
    public string Name { get; set; }
    public Team Team { get; set; }
}

But whats the best to define the 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; }
}

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about POCO