Hiyya,
We're currently working on a project where we need to locally store data (configuration data, more specifically) and figured Sqlite is a decent solution for now.
However, after setting up the DBContext, Entities and whatnot, creating a migration and running Update-Database
to create the database (and confirming through DB Browser for SQLite
that it "properly" created it), we are met with a "No such table found" error.
DataService.cs
private SettingsModel GetConfig()
{
using(var _context = new DataContext())
{
var query = (from a in _context.SettingsModel
select a);
var obj = query.FirstOrDefault();
if (string.IsNullOrWhiteSpace(obj.ExpressionString))
obj.ExpressionString = DEFAULT_EXPRESSION_STRING;
return obj;
}
}
DbContext.cs
public class DataContext : DbContext
{
public virtual DbSet<SettingsModel> SettingsModel { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite("Data source=keyconfig.db");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SettingsModel>(entity =>
{
entity.HasNoKey();
entity.Property(e => e.ExpressionString)
.IsUnicode(false);
});
}
}
SettingsModel.cs
public class SettingsModel
{
public string ExpressionString { get; set; }
}
I am honestly quite dumb-founded why this is not working (or why we're having the issue we're having), especially after confirming the database and it's table(s) does exist, so any and all help would be appreciated!