title: Generic findById with Entity Framework and composite keys
body: <p>I have this generic version of a <code>findById()</code> method (<code>KeyType</code> and <code>EntityType</code> are template parameters at the class level): </p>
  
  <pre><code>public EntityType findById(KeyType key)
  {
      log.LogDebugStart();
      log.LogDebug("id=" + key);
  
      EntityType data;
  
      using (ObjectContextWrapper contextWrapper = TransactionHelper.GetContextWrapper())
      {
          Entities bdd = contextWrapper.GetContext();
  
          DbSet&lt;EntityType&gt; set = bdd.Set&lt;EntityType&gt;();
  
          data = set.Find(key);
      }
  
      log.LogDebugEnd();
      return data;
  }
  </code></pre>
  
  <p>It works well with single-column keys (ex: KeyType = long) but I can't get it to work with composite primary key (Ex: KeyType : long[]).</p>
  
  <p>The exception I get: </p>
  
  <blockquote>
    <p>The number of primary key values passed must match number of primary
    key values defined on the entity. Parameter name: keyValues</p>
  </blockquote>
  
  <p>The entities are generated from the database with the help of an <code>.edmx</code> file. Both columns in my case are set to primary key. In the debugger, I see very well that key is of type short[2].</p>
  
  <p>I thought it could be linked with the fact that my method doesn't take a "params" argument, and that somehow the entire array would be passed as a single param to the <code>Find()</code> method, but it should be fine as long as I pass an array to my <code>findById()</code> method...</p>