I generated my classes from the database via Entity Framework. The classes name are the tables name and the properties are the fields. Now I've three tables , App_users, Book, Course.
App_users has one to many relationship with book and course (userid is foreign key). When I see the user class, it has the structure like this:
public partial class App_users
{
public App_users()
{
this.Book = new HashSet<Book>();
this.Course = new HashSet<Course>();
}
public int USERID { get; set; }
public string USERNAME { get; set; }
public virtual ICollection<Book> Book { get; set; }
public virtual ICollection<Course> Course { get; set; }
}
- I want to know that why these tables (Book & Course) are defined as HASHSET inside the constructor. What is the use/importance of doing so?
- Again the classes Book & Course are defined as ICOLLECTION. What is the use/importance of doing this?
I know that this structure is used for showing the foreign key relationship in a table.
Please can anyone explain me this.