title: SqlException: Invalid object name
body: <p>I'm getting started on a new project using EF core.
  I have an existing database on MSSQL server and I run this command in order to include its structure for EF.</p>
  
  <pre><code>Scaffold-DbContext "Server={My Server};Database={My DB};Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer
  </code></pre>
  
  <p>This has created the model classes for me, such as:</p>
  
  <pre><code>public partial class Cameras
  {
      public int CameraId { get; set; }
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>and the following context class:</p>
  
  <pre><code>public partial class SetupToolContext : DbContext
  {
      public virtual DbSet&lt;Cameras&gt; Cameras { get; set; }
  
      public SetupToolContext(DbContextOptions&lt;SetupToolContext&gt; options) : base(options)
      { }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Cameras&gt;(entity =&gt;
          {
              entity.HasKey(e =&gt; e.CameraId)
                  .HasName("PK_Cameras");
  
              entity.Property(e =&gt; e.Description).HasColumnType("varchar(500)");
          });
      }
  }
  </code></pre>
  
  <p>I have 4 layers in my solution:</p>
  
  <ul>
  <li>BusinessLogic</li>
  <li>DAL</li>
  <li>Interfaces (for dependency injection)</li>
  <li>API (controllers)</li>
  </ul>
  
  <p>Here is how the flow looks like in my code:</p>
  
  <p><strong>Controller class</strong></p>
  
  <pre><code>public class ValuesController : Controller
  {
      ICameraRepository cameraRepository;
  
      public ValuesController(ICameraRepository cameraRepository)
      {
          this.cameraRepository = cameraRepository;
      }
  
      [HttpGet]
      public IEnumerable&lt;Cameras&gt; Get()
      {
          //ERROR: "Invalid object name 'Cameras'."
          return cameraRepository.List();
      }
  }
  </code></pre>
  
  <p><strong>CameraRepository class</strong></p>
  
  <pre><code>public class CamerasRepository : GenericRepository&lt;Cameras&gt;, ICameraRepository
  {
      private readonly SetupToolContext dbContext;
  
      public CamerasRepository(SetupToolContext dbContext) : base(dbContext)
      {
          this.dbContext = dbContext;
      }
  }
  
  public interface ICameraRepository : IRepository&lt;Cameras&gt;
  { }
  </code></pre>
  
  <p><strong>GenericRepository class</strong> (to try and follow the <a href="http://deviq.com/repository-pattern/" rel="nofollow noreferrer">Repository Pattern</a>)</p>
  
  <pre><code>public class GenericRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      private readonly SetupToolContext dbContext;
  
      public GenericRepository(SetupToolContext dbContext)
      {
          this.dbContext = dbContext;
      }
  
      public IEnumerable&lt;T&gt; List()
      {
          return dbContext.Set&lt;T&gt;().AsEnumerable();
      }
  }
  
  public interface IRepository&lt;T&gt;
  {
      IEnumerable&lt;T&gt; List();
  }
  </code></pre>
  
  <p><strong>And Startup class ConfigureServices method</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext&lt;SetupToolContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("SQLServerConnection")));
      services.AddMvc();
      services.AddScoped&lt;ICameraRepository, CamerasRepository&gt;();
  }
  </code></pre>
  
  <p>The issue is that I'm getting an error: <code>"Invalid object name 'Cameras'."</code></p>
  
  <p><a href="https://i.stack.imgur.com/1xgqM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1xgqM.png" alt="Here is a screenshot of the error"></a>
  What is wrong in this process?</p>