Пример #1
0
        public static int EnsureSeedData(this DwContext context)
        {
            var bookCount       = default(int);
            var characterCount  = default(int);
            var bookSeriesCount = default(int);

            // Because each of the following seed method needs to do a save
            // (the data they're importing is relational), we need to call
            // SaveAsync within each method.
            // So let's keep tabs on the counts as they come back

            var dbSeeder = new DatabaseSeeder(context);

            if (!context.Books.Any())
            {
                var pathToSeedData = Path.Combine(Directory.GetCurrentDirectory(), "SeedData", "BookSeedData.json");
                bookCount = dbSeeder.SeedBookEntitiesFromJson(pathToSeedData).Result;
            }
            if (!context.BookCharacters.Any())
            {
                characterCount = dbSeeder.SeedBookCharacterEntriesFromJson().Result;
            }
            if (!context.BookSeries.Any())
            {
                bookSeriesCount = dbSeeder.SeedBookSeriesEntriesFromJson().Result;
            }

            return(bookCount + characterCount + bookSeriesCount);
        }
Пример #2
0
        public static bool AllMigrationsApplied(this DwContext context)
        {
            var applied = context.GetService <IHistoryRepository>()
                          .GetAppliedMigrations()
                          .Select(m => m.MigrationId);

            var total = context.GetService <IMigrationsAssembly>()
                        .Migrations
                        .Select(m => m.Key);

            return(!total.Except(applied).Any());
        }