Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Retrieve Many to Many Relationship based records using Code First Approach with LINQ To SQL?
    primarykey
    data
    text
    <p>I am using Code First LINQ To SQL Approach and trying to retrieve records from two tables by using junction table. I have structured data model in very simple way and include Foriegn Keys in the child classes as properties like "CourseId"( Course Id was primary key in Program Class).</p> <p>So My many to Many Relationship is somehow structured in classes like : </p> <p>Program (ProgramId,ProgramName) Course (CourseId,CourseName,CreditPts) ProgramCourse ( ProgramId, CourseId ) &lt;-- Junction Table</p> <p>Here's my data model.</p> <pre><code>public class ProgramCourse { [Required] public int ProgramId { get; set; } [Required] public int CourseId { get; set; } } public class Program { public int ProgramId { get; set; } [Required] [Display(Name = "Program Name")] public string ProgramName { get; set; } public int InstituteId { get; set; } // public virtual Institute Institute { get; set; } } class Course { public int CourseID { get; set; } [Required] [Display(Name = "Course Name")] public string CourseName { get; set; } [Required] [Display(Name = "Credit Points")] public string CreditPoints { set; get; } } </code></pre> <p><strong>My Problem</strong></p> <p>I am not able to retrieve the data from both tables ( i.e Program and Course ). I want to write method "GetAllCoursesForProgram" which displays the courses for specific program. Because I can't navigate towards "ProgramCourse" class from Course class or from Program class. Because foreign keys included as simple int's and there are no navigational properties included in the whole data model. If I include navigational properties , I would have problems to manipulate these object and making AJAX based calls to server from jTable.</p> <p>Any body can suggest me the solution ? How to form a query to retrieve data from multiple tables ? I would be extremely obliged. Many Thanks in advance.</p> <p>Regards Usman</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload