I want to know what is the difference between creating classes with or without using \"hashset\" in constructor.
Using code first approach (4.3) one can creat models
I'm fairly new to Entity Framework but this is my understanding. The collection types can be any type that implements ICollection
. In my opinion a HashSet is usually the semantically correct collection type. Most collections should only have one instance of a member (no duplicates) and HashSet best expresses this. I have been writing my classes as shown below and this has worked well so far. Note that the collection is typed as ISet
and the setter is private.
public class Customer
{
public Customer()
{
BrokerageAccounts = new HashSet();
}
public int Id { get; set; }
public string FirstName { get; set; }
public ISet BrokerageAccounts { get; private set; }
}