Example #1
0
        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();
        }
Example #2
0
        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();
        }