Пример #1
0
        /// <summary>
        /// OnConfiguring
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            switch (DBType)
            {
            case DBTypeEnum.SqlServer:
                optionsBuilder.UseSqlServer(CSName);
                break;

            case DBTypeEnum.MySql:
                ServerVersion sv = null;
                if (string.IsNullOrEmpty(Version) == false)
                {
                    ServerVersion.TryFromString(Version, out sv);
                }
                if (sv == null)
                {
                    sv = ServerVersion.AutoDetect(CSName);
                }
                optionsBuilder.UseMySql(CSName, sv);
                break;

            case DBTypeEnum.PgSql:
                optionsBuilder.UseNpgsql(CSName);
                break;

            case DBTypeEnum.Memory:
                optionsBuilder.UseInMemoryDatabase(CSName);
                break;

            case DBTypeEnum.SQLite:
                optionsBuilder.UseSqlite(CSName);
                break;

            case DBTypeEnum.Oracle:

                optionsBuilder.UseOracle(CSName, option => {
                    if (string.IsNullOrEmpty(Version) == false)
                    {
                        option.UseOracleSQLCompatibility(Version);
                    }
                    else
                    {
                        option.UseOracleSQLCompatibility("11");
                    }
                });
                break;

            default:
                break;
            }
            if (IsDebug == true)
            {
                optionsBuilder.EnableDetailedErrors();
                optionsBuilder.EnableSensitiveDataLogging();
                if (_loggerFactory != null)
                {
                    optionsBuilder.UseLoggerFactory(_loggerFactory);
                }
            }
            base.OnConfiguring(optionsBuilder);
        }