using hashset in entity framework
entity-framework
Solution
I'm fairly new to Entity Framework but this is my understanding. The collection types can be any type that implements `ICollection<T>`. 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<T>` and the setter is private.
public class Customer
{
public Customer()
{
BrokerageAccounts = new HashSet<BrokerageAccount>();
}
public int Id { get; set; }
public string FirstName { get; set; }
public ISet<BrokerageAccount> BrokerageAccounts { get; private set; }
}
Problem
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 like this: ``` public class Blog { public int Id { get; set; } public string Title { get; set; } public string BloggerName { get; set;} public virtual ICollection<Post> Posts { get; set; } } public class Post { public int Id { get; set; } public string Title { get; set; } public DateTime DateCreated { get; set; } public string Content { get; set; } public int BlogId { get; set; } public ICollection<Comment> Comments { get; set; } } ``` or can create models like this : ``` public class Customer { public Customer() { BrokerageAccounts = new HashSet<BrokerageAccount>(); } public int Id { get; set; } public string FirstName { get; set; } public ICollection<BrokerageAccount> BrokerageAccounts { get; set; } } public class BrokerageAccount { public int Id { get; set; } public string AccountNumber { get; set; } public int CustomerId { get; set; } } ``` What is hashset doing here? should i use hashset in the first two models also? is there any article which shows the application of hashset?