// If the database has no questions add sample questions, // answers, and an admin user public static async Task Initialize(DbContextEnq context , IServiceProvider provider, IConfiguration config) { context.Database.EnsureCreated(); if (context.Question.Any()) { return; } var userIds = await CreateUsers(provider, config); context.AddRange(GetQuestions(userIds.ToList())); context.SaveChanges(); }
public DbContextEnq GetContext() { // The first time GetContext is called a new connection will be created if (_connection == null) { _connection = new SqliteConnection(_url); _connection.Open(); using (var context = new DbContextEnq(GetOptions())) { context.Database.EnsureCreated(); // Add sample data if present if (_sampleData != null) { foreach (var command in _sampleData) { context.Database.ExecuteSqlRaw(command); } } } } return(new DbContextEnq(GetOptions())); }