Esempio n. 1
0
        // 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();
        }
Esempio n. 2
0
        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()));
        }