fgalarraga
fgalarraga

Reputation: 107

EF5 Entity Constructor

Is there a performance gain in any of the following code implementations or does it really not matter?

public class Content
{
    public Content()
    {
        Topics = new List<Topic>();
    }

    public int ContentId { get; set; }

    //Navigation Properties
    public ICollection<Topic> Topics { get; set; }
}

and

public class Content
{
    public Content()
    {
        Topics = new HashSet<Topic>();
    }

    public int ContentId { get; set; }

    //Navigation Properties
    public ICollection<Topic> Topics { get; set; }
}

The examples on MSDN mix them up just wondering if there is any difference.

Upvotes: 0

Views: 45

Answers (1)

Pawel
Pawel

Reputation: 31610

I would say it should not matter. I don't know how many items you are expecting to store in these collections but EF is connecting to a database which is probably at least a couple orders of magnitude more expensive than opertions in memory we are talking about. Instead of trying to prematurely optimize just write the code so it is clean and easy to understand and maintain. Then - if you see a performance issue - measure to find out the cause is and I am 99.9% sure it won't be on this line.

Upvotes: 1

Related Questions