title: SQLite data context in AspNetCore app not working
body: <p>I have been trying to implement data access in my single page web app using the most recent scaffolding in Visual Studio 2019 and Entity Framework Core .   I am using SDK version 3.1.100.   Everything builds and runs but I am getting a runtime exception claiming "no such table: User".   This makes me think that the connection between EF core and the database is good.  Could be anything else as I am not having much luck with debugging. My SQLite database file and sqlite3.dll are contained in the project and have properties set to copy to output.  The relevant code portions follow:</p>
  
  <p>appsettings.json:</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "Sqlite": "Data Source=HopeApp.db"
    },
    "Logging": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "AllowedHosts": "*"
  }
  </code></pre>
  
  <p>The following added to ConfigureServices in Startup.cs:</p>
  
  <pre><code>services.AddEntityFrameworkSqlite()
      .AddDbContext&lt;DatabaseContext&gt;(options =&gt;
            options.UseSqlite(Configuration.GetConnectionString("Sqlite"))); 
  </code></pre>
  
  <p>The database context:</p>
  
  <pre><code>public class DatabaseContext: DbContext
    {
      public  DbSet&lt;datUser&gt; User { get; set; }
      public  DbSet&lt;datIESum&gt; IESum { get; set; }
  
      //
      // https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext
      //
      public DatabaseContext(DbContextOptions&lt;DatabaseContext&gt; options)
              : base(options) {    }
  
    }
  </code></pre>
  
  <p>And finally, the controller that attempts to retrieve the data:</p>
  
  <pre><code>[ApiController]
  [Route("[controller]")]
  public class UserController : ControllerBase
  {
  private readonly DatabaseContext db;
  
  public UserController(DatabaseContext db)
  {
    this.db = db;
  }
  
  [HttpGet]
  public IEnumerable&lt;datUser&gt; Get()
  {
    List&lt;datUser&gt; users = new List&lt;datUser&gt;();
  
    using (this.db)
    {
      foreach (var user in this.db.User)
      {
        users.Append(user);
      }
    }
  
    return users;
    }
  }
  </code></pre>
  
  <p>I examine the SQLite .db file in DB Brower and see the tables are present and verify that data is present.  I have checked file permissions so everyone has full control.  I don't know what else to check to track this down.   Note that most of the examples these days are provided as "code first" instead of "database first" which works better for my application. </p>
  
  <p>Here is a screen shot of HopeApp.db: </p>
  
  <p><a href="https://i.stack.imgur.com/levEu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/levEu.png" alt="enter image description here"></a></p>
  
  <p>The error:</p>
  
  <pre><code>An exception of type 'Microsoft.Data.Sqlite.SqliteException' occurred in
  Microsoft.EntityFrameworkCore.Relational.dll but was not handled in user code
  SQLite Error 1: 'no such table: User'.
  </code></pre>
  
  <p>Any ideas or debugging suggestions?  Any more information I can provide?</p>