public override void Load() { var builder = new DbContextOptionsBuilder <LOTTODBContext>(); _optionsAction(builder); using (var dbContext = new LOTTODBContext(builder.Options)) { dbContext.Database.EnsureCreated(); Data = !dbContext.Configuration.Any() ? CreateAndSaveDefaultValues(dbContext) : dbContext.Configuration.ToDictionary(c => c.KeyName, c => c.KeyValue); } }
private static IDictionary <string, string> CreateAndSaveDefaultValues(LOTTODBContext dbContext) { var configValues = new Dictionary <string, string> { { "key1", "value_from_ef_1" }, { "key2", "value_from_ef_2" } }; dbContext.Configuration.AddRange(configValues .Select(kvp => new Configuration { KeyName = kvp.Key, KeyValue = kvp.Value }) .ToArray()); dbContext.SaveChanges(); return(configValues); }