コード例 #1
0
        public NccDbContext CreateDbContext(string[] args)
        {
            var opts         = SetupHelper.GetDbContextOptions();
            var nccDbConetxt = new NccDbContext(opts);

            return(nccDbConetxt);
        }
コード例 #2
0
ファイル: DatabaseFactory.cs プロジェクト: nbyh/NetCoreCMS
        public static bool InitilizeDatabase(SupportedDatabases database, string connectionString)
        {
            var builder = new DbContextOptionsBuilder <NccDbContext>();

            switch (database)
            {
            case SupportedDatabases.MSSQL:
                builder.UseSqlServer(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case SupportedDatabases.MsSqlLocalStorage:
                break;

            case SupportedDatabases.MySql:
                builder.UseMySql(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case SupportedDatabases.SqLite:
                builder.UseSqlite(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case SupportedDatabases.PgSql:
                break;
            }
            //builder.UseSqlite(connectionString, options => options.MigrationsAssembly("NetCoreCMS.Framework"));


            var dbContext = new NccDbContext(builder.Options);

            dbContext.Database.Migrate();
            return(dbContext.Database.EnsureCreated());
        }
コード例 #3
0
        public NccDbContext Create(DbContextFactoryOptions options)
        {
            var opts         = SetupHelper.GetDbContextOptions();
            var nccDbConetxt = new NccDbContext(opts);

            return(nccDbConetxt);
        }