public static void Init(IServiceProvider serviceProvider) { using var mortgageDbContext = new MortgageDbContext(serviceProvider.GetRequiredService <DbContextOptions <MortgageDbContext> >()); if (mortgageDbContext.Mortgages.Any()) { return; } mortgageDbContext.Mortgages.AddRange( new Core.Mortgage.Mortgage { Lender = "Bank A", Rate = 2, Type = "Variable", LoanToValue = 60 }, new Core.Mortgage.Mortgage { Lender = "Bank B", Rate = 3, Type = "Fixed", LoanToValue = 60 }, new Core.Mortgage.Mortgage { Lender = "Bank C", Rate = 4, Type = "Variable", LoanToValue = 90 } ); mortgageDbContext.SaveChanges(); }
void Seed(MortgageDbContext context) { context.MortgageRates.AddRange( new MortgageRate { InterestRate = 1.24, LastUpdate = DateTime.Now, MaturityPeriod = 1, }, new MortgageRate { InterestRate = 1.24, LastUpdate = DateTime.Now, MaturityPeriod = 2, }, new MortgageRate { InterestRate = 1.24, LastUpdate = DateTime.Now, MaturityPeriod = 3, }, new MortgageRate { InterestRate = 1.27, LastUpdate = DateTime.Now, MaturityPeriod = 5, }, new MortgageRate { InterestRate = 1.27, LastUpdate = DateTime.Now, MaturityPeriod = 6, }, new MortgageRate { InterestRate = 1.28, LastUpdate = DateTime.Now, MaturityPeriod = 7, }, new MortgageRate { InterestRate = 1.34, LastUpdate = DateTime.Now, MaturityPeriod = 10, }, new MortgageRate { InterestRate = 1.57, LastUpdate = DateTime.Now, MaturityPeriod = 12, }, new MortgageRate { InterestRate = 1.65, LastUpdate = DateTime.Now, MaturityPeriod = 15, }, new MortgageRate { InterestRate = 1.65, LastUpdate = DateTime.Now, MaturityPeriod = 17, }, new MortgageRate { InterestRate = 1.75, LastUpdate = DateTime.Now, MaturityPeriod = 20 }, new MortgageRate { InterestRate = 1.99, LastUpdate = DateTime.Now, MaturityPeriod = 30, } ); context.SaveChanges(); }