title: Very slow LINQ query using EF and Oracle Table
body: <p>I have an MVC3 application using EF4, hitting an Oracle backend.  I've run into a strange problem accessing one of the tables with link.  The table is called EXPENSES, and it has a identity column (type: NUMBER) called PK.  Despite its name, the PK column is not actually a Primary Key--it just has a unique index on it.  </p>
  
  <p>When I do a LINQ query against this table, it is extremely slow, even bringing back &lt; 100 records.  Here is the query:</p>
  
  <pre>
  List results = dataContext.EXPENSE.Where(x => x.PROJECT_ID == trgProjectID).ToList();
  </pre>
  
  <p>I've looked at the raw SQL it is sending to the database (using ToTraceString) and the SQL itself runs very quickly (less than 2 seconds).</p>
  
  <p>Note that my query does not include the PK column itself.  However, the PROJECT_ID column also has an index on it (a non-unique index, in this case).</p>
  
  <p>Strangely, if I "hack" the query so that I also filter on PK in my Where statement (basically, I hard-coded the PK values into it, just to see what would happen), the query completes very quickly.  </p>
  
  <p>I am guessing this problem has something to do with Key resolution inside the EF layer.  I tried changing the MergeOption on the Expenses DBSet to "NoTracking" but this has no effect.</p>
  
  <p>Any ideas would be much appreciated...!</p>