title: 'Invalid attempt to read when no data is present' - exception happens "sometimes" in Entity Framework
body: <p>I get the above error sometimes during the read.  The exception originates from ASP.NET SqlDataReader whenever you try to read data before calling the Read() method.  Since EF does all these internally, I am wondering what else can cause this error.  could it be network (or) db connectivity? </p>
  
  <p>thanks</p>
  
  <p><strong>Additional Bounty Info (GenericTypeTea):</strong></p>
  
  <p>I've got the same error after upgrading to EF Code First RC (4.1):</p>
  
  <blockquote>
    <p>"Invalid attempt to read when no data
    is present"</p>
  </blockquote>
  
  <p>This is the code in question:</p>
  
  <pre><code>using (var context = GetContext())
  {
      var query = from item in context.Preferences
                  where item.UserName == userName
                  where item.PrefName == "TreeState"
                  select item;
  
      // Error on this line
      Preference entity = query.FirstOrDefault();
      return entity == null ? null : entity.Value;
  }
  </code></pre>
  
  <p>The table structure is as follows:</p>
  
  <pre><code>Preference
  {
      Username [varchar(50)]
      PrefName [varchar(50)]
      Value [varchar(max)] Nullable
  }
  </code></pre>
  
  <p>The table is standalone and has no relationships. This is the DbModelBuilder code:</p>
  
  <pre><code>private void ConfigurePreference(DbModelBuilder builder)
  {
      builder.Entity&lt;Preference&gt;().HasKey(x =&gt; new { x.UserName, x.PrefName });
      builder.Entity&lt;Preference&gt;().ToTable("RP_Preference");
  }
  </code></pre>
  
  <p>Exactly the same code works perfectly in CTP5. I'm guessing this is an RC bug, but any ideas of how to fix it would be appreciated.</p>