title: Duplicate Rows when Data Binding with LINQ to Entities
body: <p>I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView to the results of the following LINQ to entities query.  In both cases the grids contain the correct number of rows, but the data from only the first handful of rows is duplicated in all the other rows.  I'm directly assigning the return value from this code the the DataSource property on the grids.</p>
  
  <pre><code>public IEnumerable&lt;DirectoryPersonEntry&gt; FindPersons(string searchTerm)
  {
      DirectoryEntities dents = new DirectoryEntities();
      return from dp in dents.DirectoryPersonEntrySet
             where dp.LastName.StartsWith(searchTerm) || dp.Extension.StartsWith(searchTerm)
             orderby dp.LastName, dp.Extension
             select dp;
  }
  </code></pre>
  
  <p><strong>ADDED:</strong> This is the alternate plain ADO.NET code that works:</p>
  
  <pre><code>    DataTable ret = new DataTable();
      using (SqlConnection sqn = new SqlConnection(ConfigurationManager.ConnectionStrings["WaveAdo"].ConnectionString))
      {
          SqlDataAdapter adap = new SqlDataAdapter("select * from DirectoryPersonList where LastName like '" + searchTerm + "%' order by LastName ", sqn);
          sqn.Open();
          adap.Fill(ret);
      }
      return ret;
  </code></pre>
  
  <p><strong>MORE</strong>: </p>
  
  <ol>
  <li>The query sent to SQL Server by LINQ works.  </li>
  <li>Iterating the LINQ query results before returning them results in the same duplications.</li>
  <li>Iterating the LINQ results in the calling method, before binding, results in the same duplications.</li>
  </ol>
  
  <p><strong>UPDATE</strong>:
  Based on the very logical and fitting advice from <em>Marc Gravel</em> below, I found that the EF designer had made a very uneducated guess at an Entity Key for my entity class, the first field in its list of fields, Department, of which there are only about seven entries shared across all other records.  </p>
  
  <p>This is indeed the cause of the duplication.  If only I could change or remove the entity key, but this EF designer with all the business logic of an Etch-a-Sketch is admirably committed to repeating it's retarded choice of key while laughing at me locked outside begging to change the key.</p>