Beispiel #1
7
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseSqlite($"Data Source={databaseFile};");
            optionsBuilder.EnableSensitiveDataLogging();
        }
        public InheritanceSqlServerFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddSqlServer()
                    .ServiceCollection()
                    .AddSingleton(TestSqlServerModelSource.GetFactory(OnModelCreating))
                    .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                    .BuildServiceProvider();

            var testStore = SqlServerTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder
                .EnableSensitiveDataLogging()
                .UseSqlServer(testStore.Connection);

            _options = optionsBuilder.Options;

            // TODO: Do this via migrations

            testStore.ExecuteNonQuery(@"
                CREATE TABLE Country (
                    Id int NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL
                );

                CREATE TABLE Animal (
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int NOT NULL FOREIGN KEY REFERENCES Country (Id),
                    IsFlightless bit NOT NULL,
                    EagleId nvarchar(100) FOREIGN KEY REFERENCES Animal (Species),
                    [Group] int,
                    FoundOn tinyint,
                    Discriminator nvarchar(255) NOT NULL
                );

                CREATE TABLE Plant(
                    Genus int NOT NULL,
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int FOREIGN KEY REFERENCES Country (Id),
                    HasThorns bit
                );");

            using (var context = CreateContext())
            {
                SeedData(context);
            }
        }
        protected DbContextOptions BuildOptions()
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            var sqlServerDbContextOptionsBuilder
                = optionsBuilder
                    .EnableSensitiveDataLogging()
                    .UseSqlServer(_testStore.Connection.ConnectionString);

            ConfigureOptions(sqlServerDbContextOptionsBuilder);

            sqlServerDbContextOptionsBuilder.ApplyConfiguration();

            return optionsBuilder.Options;
        }
        public NorthwindSprocQuerySqlServerFixture()
        {
            _testStore = SqlServerNorthwindContext.GetSharedStore();

            _serviceProvider = new ServiceCollection()
                .AddEntityFramework()
                .AddSqlServer()
                .ServiceCollection()
                .AddSingleton(TestSqlServerModelSource.GetFactory(OnModelCreating))
                .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder
                .EnableSensitiveDataLogging()
                .UseSqlServer(_testStore.Connection.ConnectionString);

            _options = optionsBuilder.Options;

            _serviceProvider.GetRequiredService<ILoggerFactory>()
                .MinimumLevel = LogLevel.Debug;
        }
Beispiel #5
0
        /// <inheritdoc />
        public void Configure(DbContextOptionsBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var batchSize               = this.Options.BatchSize;
            var retryCount              = this.Options.QueryRetryCount;
            var useLazyLoading          = this.Options.UseLazyLoading;
            var useSensitiveDataLogging = this.Options.UseSensitiveDataLogging;
            var connectionString        = this.Options.ConnectionString;

            var connection    = new MySqlConnection(connectionString);
            var serverVersion = ServerVersion.AutoDetect(connection);

            if (connectionString == null)
            {
                return;
            }

            builder
            .EnableSensitiveDataLogging(useSensitiveDataLogging)
            .ConfigureWarnings(x =>
            {
                x.Ignore(RelationalEventId.BoolWithDefaultWarning);
                x.Log(RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning);
            })
            .UseLazyLoadingProxies(useLazyLoading)
            .UseMySql(connection, serverVersion, x =>
            {
                x.MaxBatchSize(batchSize);
                x.EnableRetryOnFailure(retryCount);
                // x.UseNetTopologySuite(); // TODO: UseNetTopologySuite, Waiting for Pomelo.
            });
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("StartTime: " + DateTime.Now);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            DbContextOptionsBuilder <MagicContext> dbContextOptions = new DbContextOptionsBuilder <MagicContext>();

            dbContextOptions.EnableSensitiveDataLogging();
            dbContextOptions.UseSqlServer("Data Source=localhost\\SQLEXPRESS; initial catalog=MagicTG; Trusted_Connection=True", providerOptions => providerOptions.CommandTimeout(60));

            MagicContext ctxt = new MagicContext(dbContextOptions.Options);

            //DbTestInitializer db = new DbTestInitializer();
            DbInitializer db = new DbInitializer(ctxt);

            sw.Stop();
            Console.WriteLine("CompletionTime: " + DateTime.Now);
            //Console.ReadLine();

            Console.WriteLine("Completed");
            Console.WriteLine(sw.Elapsed);
            Console.ReadLine();
        }
Beispiel #7
0
        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            if (!InitializedWithOptions)
            {
                options.UseNpgsql("dummy connection string");
            }

            options.ReplaceService <IRelationalTypeMappingSource, CustomNpgsqlTypeMappingSource>();

            ((IDbContextOptionsBuilderInfrastructure)options).AddOrUpdateExtension(new SnakeCaseExtension());

            options.ConfigureWarnings(x =>
            {
                x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
#if DEBUG
                // for tests
                x.Ignore(CoreEventId.SensitiveDataLoggingEnabledWarning);
#endif
            });

#if DEBUG
            options.EnableSensitiveDataLogging();
#endif
        }
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 'ApplicationDbContext.OnConfiguring(DbContextOptionsBuilder)'
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member 'ApplicationDbContext.OnConfiguring(DbContextOptionsBuilder)'
        {
            if (!optionsBuilder.IsConfigured)
            {
                if (HostingEnvironment == null)
                {
                    string constring = "Server=(localdb)\\mssqllocaldb;Database=SINners_DB;Trusted_Connection=True;MultipleActiveResultSets=true";
                    optionsBuilder.UseSqlServer(constring);

                    //throw new ArgumentNullException("HostingEnviroment is null!");
                }
                else
                {
                    var configurationBuilder = new ConfigurationBuilder()
                                               .SetBasePath(HostingEnvironment.ContentRootPath)
                                               .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
                    Configuration = configurationBuilder.Build();
                    optionsBuilder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
                }
            }

            optionsBuilder.EnableSensitiveDataLogging();
        }
Beispiel #9
0
        public void OneTimeSetUp()
        {
            CustomOnWrite = writeContext =>
            {
                TestContext.WriteLine(writeContext);
            };

            CustomOnBeginScope = scopeContext =>
            {
                TestContext.WriteLine(scopeContext);
            };

            ServiceCollectionInstance = new ServiceCollection();
            ServiceCollectionInstance.AddTestLogger(CustomOnWrite, CustomOnBeginScope);
            ServiceCollectionInstance.AddSingleton <SqliteConnection>(fact =>
            {
                var connStr = "Filename=:memory:";
                var conn    = new SqliteConnection(connStr);
                conn.Open();
                return(conn);
            });
            ServiceCollectionInstance.AddSingleton <DbContextOptions <TestSqliteContext> >(fact =>
            {
                var conn        = fact.GetRequiredService <SqliteConnection>();
                var loggingFact = fact.GetRequiredService <ILoggerFactory>();
                var tmp         = new DbContextOptionsBuilder <TestSqliteContext>().UseSqlite(conn).UseLoggerFactory(loggingFact);
                tmp.EnableSensitiveDataLogging();
                return(tmp.Options);
            });
            ServiceCollectionInstance.AddTransient <TestSqliteContext>(fact =>
            {
                var options = fact.GetRequiredService <DbContextOptions <TestSqliteContext> >();
                var tmp     = new TestSqliteContext(options);
                return(tmp);
            });
        }
        public EFMaterialRepositoryTests()
        {
            var optionsBuilder = new DbContextOptionsBuilder <EFDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());

            optionsBuilder.EnableSensitiveDataLogging();
            var options = optionsBuilder.Options;

            _context = new EFDBContext(options);
            _context.Database.EnsureCreated();
            _materialRepository  = new EFMaterialRepository(_context);
            _directoryRepository = new EFDirectoryRepository(_context);

            TestBaseInitializer.Initialize(_context);

            optionsBuilder = new DbContextOptionsBuilder <EFDBContext>()
                             .UseInMemoryDatabase(Guid.NewGuid().ToString());
            optionsBuilder.EnableSensitiveDataLogging();
            options = optionsBuilder.Options;

            _emptyContext = new EFDBContext(options);
            _emptyContext.Database.EnsureCreated();
            _emptyMaterialRepository = new EFMaterialRepository(_emptyContext);
        }
Beispiel #11
0
 internal static void ApplyOtherOptionSettings <T>(this DbContextOptionsBuilder <T> builder)
     where T : DbContext
 {
     builder.EnableSensitiveDataLogging();
 }
Beispiel #12
0
 protected override void OnConfiguring(DbContextOptionsBuilder options)
 => options.EnableSensitiveDataLogging();
Beispiel #13
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging();
     //optionsBuilder.UseSqlServer(@"Server=(local);Database=Test;Integrated Security=True");
 }
Beispiel #14
0
  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
      optionsBuilder.UseSqlite($"Filename=Blogging.db");
      optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #15
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     //optionsBuilder.UseSqlServer("Server=db;Database=ManageAuthorBooks;User=sa;Password=Teste12345678;");
     base.OnConfiguring(optionsBuilder);
     optionsBuilder.EnableSensitiveDataLogging(true);
 }
Beispiel #16
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.EnableSensitiveDataLogging();
        }
Beispiel #17
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder
 .EnableSensitiveDataLogging()
 .UseNpgsql(NpgsqlTestStore.CreateConnectionString("Repro925"))
 .UseInternalServiceProvider(_serviceProvider);
Beispiel #18
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlite(@"Data Source = C:\Users\anton\DNP1\Session8\TodosWebAPI\Todos.db");
     optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #19
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     base.OnConfiguring(optionsBuilder.EnableSensitiveDataLogging());
     optionsBuilder.UseNpgsql("Host=my_host;Database=my_db;Username=my_user;Password=my_pw");
 }
Beispiel #20
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging(true);
 }
Beispiel #21
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlite(@"Data Source = FamilyDBASaS.db");
     optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #22
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     // name of database: Family.db    -- .db may not be needed..?
     optionsBuilder.UseSqlite("Data Source = Family.db");
     optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #23
0
        /// <summary>
        /// OnConfiguring
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            switch (DBType)
            {
            case DBTypeEnum.SqlServer:
                try
                {
                    var Configs = GlobalServices.GetRequiredService <Configs>();
                    if (Configs.IsOldSqlServer == true)
                    {
                        optionsBuilder.UseSqlServer(CSName, op => op.UseRowNumberForPaging());
                    }
                    else
                    {
                        optionsBuilder.UseSqlServer(CSName);
                    }
                }
                catch
                {
                    optionsBuilder.UseSqlServer(CSName, op => op.UseRowNumberForPaging());
                }
                break;

            case DBTypeEnum.MySql:
                optionsBuilder.UseMySql(CSName, mySqlOptions =>
                {
                    if (string.IsNullOrEmpty(Version) == false)
                    {
                        mySqlOptions.ServerVersion(Version);
                    }
                });
                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);
                break;

            default:
                break;
            }
            try
            {
                var Configs = GlobalServices.GetRequiredService <Configs>();//如果是debug模式,将EF生成的sql语句输出到debug输出
                if (Configs.IsQuickDebug)
                {
                    optionsBuilder.EnableDetailedErrors();
                    optionsBuilder.EnableSensitiveDataLogging();
                    optionsBuilder.UseLoggerFactory(LoggerFactory);
                }
            }
            catch { }
            base.OnConfiguring(optionsBuilder);
        }
Beispiel #24
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseLoggerFactory(loggerFactory);
     optionsBuilder.EnableSensitiveDataLogging();
     optionsBuilder.UseSqlite("Data Source=DB\\Database.db");
 }
Beispiel #25
0
 protected override void OnConfiguring(DbContextOptionsBuilder options)
 {
     // connect to sql server database
     options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
     options.EnableSensitiveDataLogging();
 }
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging();
     optionsBuilder.UseLoggerFactory(LoggerFactory);
 }
Beispiel #27
0
 /// <inheritdoc/>
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlite($"Filename={this.dbPath};");
     optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #28
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlServer(GetConnectionString());
     optionsBuilder.EnableSensitiveDataLogging();
     optionsBuilder.UseLazyLoadingProxies();
 }
Beispiel #29
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
     optionsBuilder.EnableSensitiveDataLogging(true);
     optionsBuilder.UseSqlite("Data Source=tracersdb.db");
 }
Beispiel #30
0
 protected override void OnConfiguring(DbContextOptionsBuilder options)
 {
     base.OnConfiguring(options);
     options.UseSqlite("Data Source=cells.db");
     options.EnableSensitiveDataLogging();
 }
        // public MovieContext(DbContextOptions<MovieContext> options) : base(options) {

        // }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Data Source=SFF.db");
            optionsBuilder.EnableSensitiveDataLogging();
            // optionsBuilder.UseInMemoryDatabase("movies");
        }
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging();
     optionsBuilder.UseSqlServer(_connectionString);
 }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder_)
        {
#if DEBUG
            base.OnConfiguring(optionsBuilder_.EnableSensitiveDataLogging().UseLoggerFactory(GetLoggerFactory()));
#endif
        }
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder
     .EnableSensitiveDataLogging()
     .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test");
 }
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     base.OnConfiguring(optionsBuilder);
     optionsBuilder.EnableSensitiveDataLogging();
 }
Beispiel #36
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging();
     optionsBuilder.UseSqlite("data source=player.db", options => { });
 }
        public static IDbContextOptions CreateOptions(
            FakeRelationalOptionsExtension optionsExtension = null, bool logParameters = false)
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            if (logParameters)
            {
                optionsBuilder.EnableSensitiveDataLogging();
            }

            ((IDbContextOptionsBuilderInfrastructure)optionsBuilder)
                .AddOrUpdateExtension(optionsExtension ?? new FakeRelationalOptionsExtension { ConnectionString = ConnectionString });

            return optionsBuilder.Options;
        }