title: How can I query an ID-Name pair in LINQ for duplicate names?
body: <p>I have a LINQ to Objects query that returns a list of:</p>
  
  <pre><code>class EmpMasterIDocBuffer
  {
    public int Index { get; set; }
    public Int64 AutoId { get; set; }
    public string Buffer { get; set; }
  }
  </code></pre>
  
  <p>It is correctly ordered so that duplicate Buffer values will be easily visible in a grid, but how can I query it? AutoId will also be duplicate when Buffer is duplicate, e.g. </p>
  
  <p>1 - Fred</p>
  
  <p>2 - Mary</p>
  
  <p>2 - Mary</p>
  
  <p>3 - Jane</p>
  
  <p>4 - Bill</p>
  
  <p>But Index will always be unique.</p>
  
  <p>I have removed <code>Index</code>, as it was just an idea I was toying with, but this is my actual code, and it returns zero items, while I know there are at least three identical classes.</p>
  
  <pre><code>var docs = ctx.Database.SqlQuery&lt;SapIdocEmployeeNumber&gt;("select AutoId, IDoc.query('data(ZHREMPMASTER/IDOC/ZHRSA_EMPMASTER01000/BUFFER)') AS Buffer from SAPIDocs").Where(i =&gt; !string.IsNullOrWhiteSpace(i.EmployeeNumber)).ToList();
  var lastDup = docs
    //.Where(i =&gt; i.AutoId == 42)
    .GroupBy(i =&gt; i.EmployeeNumber)
    .Where(g =&gt; g.Count() &gt; 1)
    .Select(g =&gt; g.Last());
  </code></pre>
  
  <p>Pasting this has given me a clue! I must only check for duplicates in the first eight characters.</p>