title: C# Entity Framework SQL Query
body: <p>I have the following models:</p>
  
  <pre><code>class Student
  {
          /// &lt;summary&gt;
          /// Student's name.
          /// &lt;/summary&gt;
          [Required]
          public string StudentName { get; set; }
  
          /// &lt;summary&gt;
          /// Student's ID
          /// &lt;/summary&gt;
          [Key]
          [Required]
          public string StudentID{get; set; }
  }
  
  class Course
  {
      [Key]
      [Required]
      public string nm { get; set; }
      [Required]
      public string CourseName { get; set; }
      [Required]
      public string Lecturer { get; set; }
      [Required]
      public string Campus { get; set; }
  }
  
  class StudentsCourses
  {
      [Key]
      [Required]
      public string nm { get; set; }
      [Required]
      public string CourseName { get; set; }
      [Required]
      public string StudentID { get; set; }
  }
  </code></pre>
  
  <p>and corresponding tables in SQL Server. Entity Framework and the models are working perfectly, but now I want to cross check data from two tables, students and courses. </p>
  
  <p>I wrote:</p>
  
  <pre><code>StringBuilder st = new StringBuilder("SELECT Students.StudentID,Students.StudentName").Append(" FROM Students, StudentsCourses");
  st.Append(" WHERE Students.StudentID=StudentsCourses.StudentID AND StudentsCourses.CourseName='").Append(course).Append("'");
  
  List&lt;Student&gt; Try = DataLayer.Students.SqlQuery(st.ToString()).ToList&lt;Student&gt;();
  </code></pre>
  
  <p>but it throws an exception saying  </p>
  
  <blockquote>
    <p>Incorrect syntax near '.'</p>
  </blockquote>
  
  <p>How can I run this query in SQL or in LinQ? My final goal is to get a list of students that study a given course name.</p>