Example #1
0
 public static DbContextOptionsBuilder UseSql(this DbContextOptionsBuilder builder,
                                              DbServerTypes serverType,
                                              string connectionString)
 {
     return(serverType == DbServerTypes.Sqlite
         ? builder.UseSqlite(connectionString)
         : builder.UseSqlServer(connectionString));
 }
Example #2
0
 public ChessGamesDbContext(
     DbServerTypes serverType,
     string connectionString,
     ILoggerFactory loggerFactory = null)
     : base(new DbContextOptionsBuilder()
            .UseSql(serverType, connectionString)
            .Options)
 {
     _loggerFactory = loggerFactory;
 }
Example #3
0
        /// <summary>
        /// Add a SQL based ChessGamesDbContext to the container
        /// </summary>
        /// <param name="services"></param>
        /// <param name="serverType"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static IServiceCollection AddChessDatabaseContext(
            this IServiceCollection services,
            DbServerTypes serverType,
            string connectionString)
        {
            return(services.AddDbContext <ChessGamesDbContext>(
                       opts =>
            {
                switch (serverType)
                {
                case DbServerTypes.SqlServer:
                    opts.UseSqlServer(connectionString);
                    break;

                case DbServerTypes.Sqlite:
                    opts.UseSqlite(connectionString);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(serverType), serverType, null);
                }
            }));
        }