Esempio n. 1
0
        private static SiremGyDbContext GetDbContext()
        {
            DbContextOptionsBuilder <SiremGyDbContext> dbContextOptionsBuilder = new DbContextOptionsBuilder <SiremGyDbContext>();

            dbContextOptionsBuilder.UseSqlite("Data Source=../../../../SiremGy.db");
            var x = new SiremGyDbContext(dbContextOptionsBuilder.Options);

            x.Database.EnsureDeleted();
            x.Database.Migrate();
            return(x);
        }
Esempio n. 2
0
        public void ConfigureDbContext(IServiceCollection services)
        {
            string connectionString = _configuration.GetConnectionString("DatabaseConnection");

            DbContextOptionsBuilder <SiremGyDbContext> dbContextOptionsBuilder = null;

            services.AddDbContext <SiremGyDbContext>(options => options.UseSqlite(connectionString));

            dbContextOptionsBuilder = new DbContextOptionsBuilder <SiremGyDbContext>();
            dbContextOptionsBuilder.UseSqlite(connectionString);

            using (SiremGyDbContext siremGyDbContext = new SiremGyDbContext(dbContextOptionsBuilder.Options))
            {
                siremGyDbContext.Database.Migrate();
                siremGyDbContext.Initialize();
            }
        }