i have the following classes
public class Subject{ public int SubjectId { get; set; } public String SubjectName { get; set; } public String SubjectCategory { get; set; } } public class QuestionDescriptor { public int QuestionDescriptorId { get; set; } public String QuestionText { get; set; } public String Answer { get; set; } public int SubjectId { get; set; } public virtual Subject Subject { get; set; } } i have configured it using the following code ,i want that a Subject can have many QuestionDescriptors
modelBuilder.Entity<QuestionDescriptor>() .HasRequired(qd => qd.Subject) .WithMany() .HasForeignKey(qd => qd.SubjectId) .WillCascadeOnDelete(true); Now i have the following question
- have i done it correctly ?
- do i need a navigation property in the Subject class?
what happems if i do this
public class Subject { public int SubjectId { get; set; } public String SubjectName { get; set; } public String SubjectCategory { get; set; } public int QuestionDescriptorId {get;set;} public virtual QuestionDescriptor {get;set;} }if i do the above what changes do i need in the configuration and why?
- if i want all the questions belonging to a particular subject then i can get them by querying the QuestionDescriptor ,why then do i need a bi-directional property ?