title: MVC Entity Framework Models and Relationships
body: <p>im quite new to ASP.net and entity framework. I created a class but im just going to simplify it and take the example class from Microsoft. So here we go. These are all the example classes</p>
  
  <pre><code>    public class Student
  {
      public int ID { get; set; }
      public string LastName { get; set; }
      public string FirstMidName { get; set; }
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
      public DateTime EnrollmentDate { get; set; }
  
      public virtual ICollection&lt;Enrollment&gt; Enrollments { get; set; }
  }
  
  
      public class Instructor
  {
      public int ID { get; set; }
  
      [Required]
      [Display(Name = "Last Name")]
      [StringLength(50)]
      public string LastName { get; set; }
  
      [Required]
      [Column("FirstName")]
      [Display(Name = "First Name")]
      [StringLength(50)]
      public string FirstMidName { get; set; }
  
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
      [Display(Name = "Hire Date")]
      public DateTime HireDate { get; set; }
  
      [Display(Name = "Full Name")]
      public string FullName
      {
          get { return LastName + ", " + FirstMidName; }
      }
  
      public virtual ICollection&lt;Course&gt; Courses { get; set; }
      public virtual OfficeAssignment OfficeAssignment { get; set; }
  }
  
  
  
  
  
     public class OfficeAssignment
      {
          [Key]
          [ForeignKey("Instructor")]
          public int InstructorID { get; set; }
          [StringLength(50)]
          [Display(Name = "Office Location")]
          public string Location { get; set; }
  
          public virtual Instructor Instructor { get; set; }
      }
  
  
  
  
     public class Course
  
  
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Name = "Number")]
        public int CourseID { get; set; }
  
        [StringLength(50, MinimumLength = 3)]
        public string Title { get; set; }
  
        [Range(0, 5)]
        public int Credits { get; set; }
  
        public int DepartmentID { get; set; }
  
        public virtual Department Department { get; set; }
        public virtual ICollection&lt;Enrollment&gt; Enrollments { get; set; }
        public virtual ICollection&lt;Instructor&gt; Instructors { get; set; }
     }
  </code></pre>
  
  <p>Like i said this is just for a example im trying to get know it. </p>
  
  <p>My First Question: Do you need something like DepartmentID When you already do public virtual Department Department?</p>
  
  <p>Second question: When i have a Collection of data how do i add values or Ids to that collection in the controller i can find this anywhere.</p>
  
  <p>Third Question: Can some one link me a complete MVC example application with proper relationships</p>