Click here to Skip to main content
15,885,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,

I am working on a class file that uses entity framework 6,

I have two object files
roles.cs and task.cs

role.cs is like
C#
public partial class Role
    {
        public Role()
        {
            this.Tasks = new HashSet<Task>();
            this.Users = new HashSet<User>();
        }

        public int RoleID { get; set; }
        public string RoleName { get; set; }

        public virtual ICollection<Task> Tasks { get; set; }
      
    }

task.cs is like

C#
public partial class Task
   {
       public Task()
       {
           this.Users_Tasks = new HashSet<Users_Tasks>();
           this.Roles = new HashSet<Role>();
       }

       public int TaskID { get; set; }
       public string TaskName { get; set; }
       public string TaskDescription { get; set; }

      
       public virtual ICollection<Role> Roles { get; set; }
   }



I want add task to role ,
please help me,
thanks and regards
Posted

1 solution

try adding the role Id to the task class

C#
public partial class Task
   {
       public Task()
       {
           this.Users_Tasks = new HashSet<Users_Tasks>();
           this.Roles = new HashSet<Role>();
       }

       public int TaskID { get; set; }
       public string TaskName { get; set; }
       public string TaskDescription { get; set; }
       
       // Foreign key 
       public int RoleID { get; set; }
       
      // Navigation properties 
       public virtual Roles Roles{ get; set; 
   }
 
Share this answer
 

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