ahmed salah

ahmed salah

  • NA
  • 530
  • 148.3k

How to represent many to many relation between student&class

Nov 15 2016 8:06 PM
Problem
I have two table Student and class many to many relationship 
 
Student Table but i dont know how to represent Classroom_Student class in code .
  1. Student Class  
  2. namespace UniversityData.Models    
  3. {    
  4.     [Table("Student")]    
  5.     public partial class Student    
  6.     {    
  7.         public Student()    
  8.         {    
  9.             this.Classes = new HashSet();    
  10.         }    
  11.         [DatabaseGenerated(DatabaseGeneratedOption.None)]    
  12.         [Key]    
  13.         public int StudentID { getset; }    
  14.     
  15.         [Required]    
  16.         [StringLength(50)]    
  17.         public String StudentName { getset; }    
  18.         public ICollection Classes { getset; }    
  19.             
  20.     
  21.     
  22.     }    
  23. }    
  24. ClassRoom Table  
  25. namespace UniversityData.Models    
  26. {    
  27.     [Table("Class")]    
  28.     public partial class Class    
  29.     {    
  30.         public Class()    
  31.         {    
  32.             this.Students = new HashSet();    
  33.         }    
  34.         [Key]    
  35.         public int ClassID { getset; }    
  36.     
  37.         [Required]    
  38.         [StringLength(50)]    
  39.         public string ClassName { getset; }    
  40.         public ICollection Students {getset;}    
  41.           
  42.     }    
  43. }    
Classroom_Student
  1. StudID
    ClassID
    starttime
    endtime
    day
    What i do as following
    Create class for Student Table and class for ClassRoom Table
    but Classroom_Student Table cannot do class for him
    how to do class for Classroom_Student Table .

Answers (9)