title: Lambda Expression joining another table in my query for average
body: <p>I am trying to join a table (db.Students) within this query to get firstname and lastname included in the query by joining on the StudentID. How do I do this? I've come up with about 50 queries that don't work and one that only gives me half of what I want. This is what I have so far that is working. </p>
  
  <pre><code>            var gradeaverages = db.Grades
                  .Where(r =&gt; r.StudentID == r.StudentID)
                  .GroupBy(g =&gt; g.StudentID, r =&gt; r.Grades)
                  .Select(g =&gt; new
                  {
                      StudentID = g.Key,
                      Rating = g.Average()
                  });
          var data = gradeaverages.ToList();
          dataGridView1.DataSource = data;   
  </code></pre>
  
  <p>It does have a foreign key. Here is the constraint: 
  CONSTRAINT [FK_Grades_Students] FOREIGN KEY ([StudentID]) REFERENCES [dbo].[Students] ([StudentID]) </p>
  
  <p>Here are my tables: </p>
  
  <pre><code>CREATE TABLE [dbo].[Grades] (
  [GradeID]   INT          NOT NULL,
  [StudentID] INT          NOT NULL,
  [Date]      NCHAR (10)   NULL,
  [Grades]    DECIMAL (18) NULL,
  PRIMARY KEY CLUSTERED ([GradeID] ASC),
  CONSTRAINT [FK_Grades_Students] FOREIGN KEY ([StudentID]) REFERENCES [dbo].[Students] ([StudentID])
  
  
  CREATE TABLE [dbo].[Students] (
  [StudentID]  INT           NOT NULL,
  [First Name] NVARCHAR (40) NOT NULL,
  [Last Name]  NVARCHAR (40) NOT NULL,
  [Phone]      NVARCHAR (24) NULL,
  CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED ([StudentID] ASC)
  </code></pre>
  
  <p>I'm looking for an out put of</p>
  
  <p>StudentID    FirstName   LastName     AverageGrade (according to StudentID I assume) </p>