private void InsertOrUpdateData(ConfigDbContext dbContext) { var values = dbContext.ConfigurationValues.ToArray(); dbContext.ConfigurationValues.RemoveRange(values); dbContext.ConfigurationValues.AddRange(Data .Select(kvp => new ConfigurationValue { Key = kvp.Key, Value = kvp.Value }) .ToArray()); dbContext.SaveChanges(); }
public override void Set(string key, string value) { var builder = new DbContextOptionsBuilder <ConfigDbContext>(); Source.OptionsAction(builder); using (var dbContext = new ConfigDbContext(builder.Options)) { dbContext.ConfigurationValues.Add(new ConfigurationValue() { Key = key, Value = value }); dbContext.SaveChanges(); } Load(); }