EF7 sqlite create table if not exists

c# entity-framework-core sqlite

Question

using c# entity framework 7 with sqlite, how can I check to see if a table exists and if not create it? Maybe based off a dbset that is in the context? There is no existing database with a migration or anything. The app just creates the database when its not there and I'd like to to also create the tables.

public class Context : DbContext
{
    public DbSet<Value> Values { get; set; }


    protected override async void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite("Filename=data.db");

        //here somewhere?
    }
}
1
0
1/1/2017 3:47:43 AM

Popular Answer

If you are not using migrations, you can use this in your app startup procedure:

context.Database.EnsureCreated();

Or with Migrations:

context.Database.Migrate();
1
1/1/2017 2:55:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow