mvc 6 ef7 Customer table object is null in AppDbContext - there is data in the database
<p>When I enter URL localhost:xxx/api/Customers, it showed "is null".  I looked at the variable in debugger mode, it show the table customers object is null;</p>

<p><img src="https://i.stack.imgur.com/IRt86.png" alt="debug image"> </p>

<p>Remember there is data in the table. Any idea?</p>

<p>Customer class</p>

<pre><code>public class Customer
{
    public string Id { get; set; }
    public string lName { get; set; }
}
</code></pre>

<p>appsettings.json</p>

<pre><code>{
"Data": {
"DefaultConnection": {
  "ConnectionString": "Server=.\\sqlexpress;Database=EF7;Trusted_Connection=True;"
}
}
</code></pre>

<p>AppDbContext</p>

<pre><code>public class AppDbContext : DbContext
{
    public DbSet&lt;Customer&gt; Customers;
    protected override void OnModelCreating(ModelBuilder Builder)
    {
        Builder.Entity&lt;Customer&gt;().HasKey(c =&gt; c.Id);
        base.OnModelCreating(Builder);
    }
 }
</code></pre>

<p>CustomersController</p>

<pre><code>[Route("api/[controller]")]
public class CustomersController : Controller
{
    AppDbContext _ctx { get; set; }
    public CustomersController([FromServices] AppDbContext ctx)
    {
        _ctx = ctx;
    }
    // GET: api/values
    [HttpGet]
    public JsonResult Get()
    {
        if(_ctx.Customers!=null)
            return Json(_ctx.Customers.ToList());
        else {
            return Json("is null");
        }
    }
}
</code></pre>

<p>Startup.cs</p>

<pre><code>public class Startup
{
    IConfigurationRoot Configuration;
    public Startup(IHostingEnvironment env)
    {
        var Builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = Builder.Build();
    }
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddEntityFramework().AddSqlServer().AddDbContext&lt;AppDbContext&gt;(o=&gt;o.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.UseMvc();
    }

    // Entry point for the application.
    public static void Main(string[] args) =&gt; WebApplication.Run&lt;Startup&gt;(args);
}
</code></pre>