Exemple #1
0
        /// <summary>
        /// 确保数据库和表已创建
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="schemas">方案</param>
        /// <returns></returns>
        public static bool EnsureCreated([NotNull] this DatabaseFacade database, string[] schemas)
        {
            Check.NotNull(database, nameof(database));
            if (schemas == null || schemas.Length == 0)
            {
                return(database.EnsureCreated());
            }
            OracleDatabaseCreator oracleDatabaseCreator = (OracleDatabaseCreator)database.GetService <IRelationalDatabaseCreator>();

            using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
            {
                if (!oracleDatabaseCreator.Exists())
                {
                    oracleDatabaseCreator.Create();
                    oracleDatabaseCreator.CreateTables();
                    return(true);
                }
                if (!oracleDatabaseCreator.HasTablesWithSchemaOption(schemas))
                {
                    oracleDatabaseCreator.CreateTables();
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 确保被删除
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="schemas">方案</param>
        /// <returns></returns>
        public static bool EnsureDeleted([NotNull] this DatabaseFacade database, string[] schemas)
        {
            Check.NotNull(database, nameof(database));

            if (schemas == null || schemas.Length == 0)
            {
                return(database.EnsureDeleted());
            }
            OracleDatabaseCreator oracleDatabaseCreator = (OracleDatabaseCreator)database.GetService <IRelationalDatabaseCreator>();

            if (oracleDatabaseCreator.Exists())
            {
                oracleDatabaseCreator.DeleteWithSchemaOption(schemas);
                return(true);
            }
            return(false);
        }