Click here to Skip to main content
15,886,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
When creating classes via entity framework for the database tables, I got the following structure of the class.
I have two tables, app_user and expenses. there is one-to-many relationship from app_user to expenses table i.e. one app_user has many expenses.
I got the following classes:
C#
public partial class app_user
    {
        public app_user()
        {
            this.expenses = new HashSet<expens>();
        }

        public int id { get; set; }
        public string username { get; set; }
        public string password { get; set; }
        public byte user_role { get; set; }
        public string is_active { get; set; }
        public Nullable<System.DateTime> date_of_register { get; set; }

        public virtual ICollection<expens> expenses { get; set; }
    }


This class structure is used for foreign key reference in table. I want to know that,
1. why in constructor, only the foreign key reference table is defined as HASHSET?
2. what is the use of doing this, why use HASHSET?
3. why the get set property of foreign key reference table is defined as ICollection?
What is the use of doing this?

Please donot provide the definition of hashset and ICollection, I already know that. I want to know why here it is done like this? defining foreign key reference table as hashset and for property ICollection?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900