コード例 #1
0
ファイル: Program.cs プロジェクト: Gor-Solomon/SiremGy
        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);
        }
コード例 #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();
            }
        }