Beispiel #1
0
        public static OnlineStoreDbContext GetOnlineStoreDbContextInMemory(string dbName)
        {
            // Create options for DbContext
            // Use in memory provider
            // Disable transactions because in memory database doesn't support txns
            var options = new DbContextOptionsBuilder <OnlineStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning))
                          .Options;

            var dbContext = new OnlineStoreDbContext(options);

            // Seed data for DbContext instance
            dbContext.SeedInMemory();

            return(dbContext);
        }