When I tried to get entities from database with the EF db context I have NullReferenceException:
Here is my testing code:
// it works fine
using (var sql = new SqlConnection("--here is my connection string--"))
{
    sql.Open();
    var cmd = sql.CreateCommand();
    cmd.CommandText = "select field1, field2 from my_table";
    var reader = cmd.ExecuteReader();
    reader.Read();
    // here is true value
    var val = reader.GetValue(0);
}
// failed
var ctx = new BackupDbContext();
var query = ctx.Database.SqlQuery<MyEntity>("select field1, field2 from my_table");
var res = query.ToList(); // NullReferenceException
// failed
var tt = ctx.MyEntities.ToList(); // NullReferenceException
My DbContext and mapping:
public class MyEntityMapping : EntityTypeConfiguration<MyEntity>
{
    public MyEntityMapping()
    {
        ToTable("my_table");
        HasKey(p => p.Field1);
        Property(p => p.Field1).HasColumnName("field1");
        Property(p => p.Field2).HasColumnName("field2");
    }
}    
public class BackupDbContext: DbContext
{
    static BackupDbContext()
    {
        Database.SetInitializer<BackupDbContext>(null);
    }
    public BackupDbContext():base("name=BackupDbContext")
    {
        Database.Log = sql => Debug.Write(sql);
    }
    public virtual DbSet<MyEntity> MyEntities { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("dbo");
        modelBuilder.Configurations
                .Add(new MyEntityMapping());
    }
}
I have no idea what is the reason of the exception.
I have the following stack trace:
Does anyone have idea why it is so or can give me a hint?
Edit:
Connection: ...
<connectionStrings>
<add name="BackupDbContext" connectionString="Data Source=My_datasource;Encrypt=False;Initial Catalog=my_db;Integrated Security=True;" providerName="System.Data.SqlClient" />      
</connectionStrings>


 
    