title: Entity Framework field query slow
body: <p>I'm having some trouble working with a particular ef query.  I've simplified everything down as much as I can.  I'm only querying for two columns.  Here is my model.</p>
  
  <pre><code>[Table("TAXROLL", Schema = "CLAND")]
  public class TaxRoll
  {
      [Key]
      [Column("TAXROLL_ID")]
      public string Id { get; set; }
  
      [Column("APN")]
      public string APN { get; set; }
  }
  </code></pre>
  
  <p>When I execute my query in my controller, if I do firstordefault, the results take as long as 15-18 seconds to return.  If I do a where query, the results are almost instantaneous (less than 1 second), (see my commented timing statements below.  When I say 15-18 seconds and almost instantaneous, that's where my numbers are coming from).</p>
  
  <pre><code>    [ResponseType(typeof(TaxRoll))]
      public async Task&lt;IHttpActionResult&gt; Get(string id)
      {
          //var start = DateTime.Now;
          //Debug.WriteLine("Starting Query");
          var apnRecord = await ctx.TaxRoll.FirstOrDefaultAsync(x =&gt; x.APN == id);
          //Debug.WriteLine("Returning APN after " + DateTime.Now.Subtract(start).TotalSeconds);
          return Ok(apnRecord);
      }
  </code></pre>
  
  <p>When I query for the primary key (Id), results return consistently fast every single time regardless of how I run the query.  This is only a problem when I'm querying for APN.  Yes, APN is indexed.  It's also unique.  I could use it as PK, and in fact I tried that.  No dice.  I know that executing a query that searches based on APN consistently returns fast when I do it directly against the database.  </p>
  
  <p>Any help or direction is greatly appreciated -- I am thoroughly confused.</p>