title: Using Linq to select maximum value in a group
body: <p><strong>Oh, I just find that the error is caused by another part of code.
  Case closed.</strong></p>
  
  <p>I have 2 tables</p>
  
  <p>1- userinfo</p>
  
  <pre><code>id uid name 
  1 11 Billy
  2 22 Paul
  3 33 Joshua
  </code></pre>
  
  <p>2- Score</p>
  
  <pre><code> id uid score
   1  11  30
   2  22  40
   3  11  50
   4  11  60
   5  33  20
   6  33  70
   7  33  80
  </code></pre>
  
  <p>I have a class called ScoreUser</p>
  
  <pre><code>public class ScoreUser{
  public long uid{get; set;}
  public string name{get;set;}
  public int score{get;set;}
  }
  </code></pre>
  
  <p>I want to use linq to query the above two tables, get the maximum score of each user and map it into the ScoreUser Object.
  I use the following code:</p>
  
  <pre><code>from s in Scores
  join i in UserInfos
  on s.uid equals i.uid
  group uscore by new { s.uid, i.name} into g
  let maxScore = g.Max(p =&gt; p.score)
  select new ScoreUser
  {
  uid = g.Key.uid,
  name = g.Key.name,
  score = maxScore
   }
  </code></pre>
  
  <p>However, this code does does not work. It produces 7 objects instead of 3.
  What should I do?</p>