コード例 #1
0
        public override void Load()
        {
            var builder = new DbContextOptionsBuilder <EFConfigurationContext>();

            OptionAction(builder);

            using (var dbContext = new EFConfigurationContext(builder.Options))
            {
                dbContext.Database.EnsureCreated();

                Data = !dbContext.Values.Any()
                    ? CreateAndSaveDefaultValues(dbContext)
                    : dbContext.Values.ToDictionary(c => c.Id, c => c.Value);
            }
        }
コード例 #2
0
        private IDictionary <string, string> CreateAndSaveDefaultValues(EFConfigurationContext dbContext)
        {
            var configValues = new Dictionary <string, string>
            {
                { "quote1", "I aim to misbehave." },
                { "quote2", "I swallowed a bug." },
                { "quote3", "You can't stop the signal, Mal." }
            };

            dbContext.Values.AddRange(configValues.Select(kvp =>
                                                          new EFConfigurationValue
            {
                Id    = kvp.Key,
                Value = kvp.Value
            }).ToArray());
            dbContext.SaveChanges();

            return(configValues);
        }