示例#1
0
        public static async Task EnsureSeedDataAsync(RmsDbContext rmsDbContext,
                                                     ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                if (!rmsDbContext.Users.Any())
                {
                    var user = new User()
                    {
                    };
                    rmsDbContext.Add(user);
                    await rmsDbContext.SaveChangesAsync();
                }

                var dataText = System.IO.File.ReadAllText(@"docs\Countries.json");
                if (!rmsDbContext.Countries.Any())
                {
                    var countries = JsonConvert.DeserializeObject(dataText);
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <RmsDbContextSeedData>();
                    log.LogError(ex.Message);
                    await EnsureSeedDataAsync(rmsDbContext, loggerFactory, retryForAvailability);
                }
            }
        }
示例#2
0
        public static bool AllMigrationsApplied(this RmsDbContext rmsDbContext)
        {
            var applied = rmsDbContext.GetService <IHistoryRepository>().GetAppliedMigrations()
                          .Select(m => m.MigrationId);
            var total = rmsDbContext.GetService <IMigrationsAssembly>().Migrations.Select(m => m.Key);

            return(!total.Except(applied).Any());
        }
示例#3
0
 public EfRepository(RmsDbContext dbContext)
 {
     DbContext = dbContext;
 }
示例#4
0
 public static void EnsureSeeded(this RmsDbContext rmsDbContext)
 {
 }