public static void Initialize(IServiceProvider serviceProvider) { using (var context = new ExchangeRateDBContext( serviceProvider.GetRequiredService <DbContextOptions <ExchangeRateDBContext> >())) { if (context.ExchangeRates.Any()) { return; } context.ExchangeRates.AddRange( new ExchangeRate { id = 1, currency_input = "SOLES", currency_output = "DOLARES", exchange_rate = 0.3M }, new ExchangeRate { id = 2, currency_input = "DOLARES", currency_output = "SOLES", exchange_rate = 3M }); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new ExchangeRateDBContext( serviceProvider.GetRequiredService <DbContextOptions <ExchangeRateDBContext> >())) { if (context.ExchangeRates.Any()) { return; } context.ExchangeRates.AddRange( new ExchangeRate { id = 1, currency_input = 1, currency_output = 2, exchange_rate = 0.3M }); if (context.Currencies.Any()) { return; } context.Currencies.AddRange( new Currency { id = 1, name = "PEN S/. - Peruvian Nuevo Sol" }, new Currency { id = 2, name = "USD $ - US Dollar" }); context.SaveChanges(); } }