I've followed the instructions on how to wire this up using the docs provided by MS. However, I am not having any success getting the data from the database.
The error I am receiving is this:
Microsoft.Data.Sqlite.SqliteException: SQLite Error 1: 'no such table: ModelRecords'.
I setup the DBContext like so:
public class SsimDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string db_file = Environment.GetEnvironmentVariable("DocumentUpdaterDbLocation");
Console.WriteLine(File.Exists(db_file) ? $"Database found at {db_file}" : $"Could not find database at {db_file}");
optionsBuilder.UseSqlite($"Filename={db_file}");
}
public DbSet<ST_Record> ModelRecords { get; set; }
}
The difference here is that I get path to the database from an environmental variable. When I write this variable to the console, it shows the path that I am expecting to the database:
Database found at C:\develop\temp\LFReview\sdb\MasterSdb.sdb
The ST_Record table is defined as:
public class ST_Record
{
[Key]
public int ST_RecordID { get; set; }
public int ProjectID { get; set; }
public string Name { get; set; }
public int ID { get; set; }
public string Description { get; set; }
}
Running this query in the database:
SELECT COUNT(*) FROM ST_Record;
Returns:
COUNT(*)
1808
Finally, the error is thrown here:
List<ST_Record> stt = _context.ModelRecords.Select(r => r).ToList();
Can anybody tell me what I am doing wrong here?
Thanks