Sometimes I get the above error while reading. An exception is thrown from the ASP.NET SqlDataReader whenever you try to read data before calling the Read () method. Since EF does all this internally, I wonder what else might cause this error. could it be network (or) db connectivity?
thanks
Additional information about the bounty (GenericTypeTea):
I have the same error after upgrading to EF Code First RC (4.1):
"Invalid read attempt when no data is present"
This is the code in question:
using (var context = GetContext()) { var query = from item in context.Preferences where item.UserName == userName where item.PrefName == "TreeState" select item;
The structure of the table is as follows:
Preference { Username [varchar(50)] PrefName [varchar(50)] Value [varchar(max)] Nullable }
The table is autonomous and has no relationship. This is the DbModelBuilder code:
private void ConfigurePreference(DbModelBuilder builder) { builder.Entity<Preference>().HasKey(x => new { x.UserName, x.PrefName }); builder.Entity<Preference>().ToTable("RP_Preference"); }
Exactly the same code works fine in CTP5. I assume this is an RC bug, but any ideas on how to fix it will be appreciated.
Saravanan
source share