示例#1
0
 /// <summary>
 /// 初始化数据库
 /// </summary>
 /// <param name="dbContext"></param>
 /// <returns></returns>
 private IDictionary <string, string> Initialize(ApplicationSettingsContext dbContext)
 {
     foreach (var item in _initialSettings)
     {
         dbContext.Settings.Add(new ApplicationSetting(item.Key, item.Value));
     }
     dbContext.SaveChanges();
     return(_initialSettings.ToDictionary(it => it.Key, it => it.Value, StringComparer.OrdinalIgnoreCase));
 }
示例#2
0
        public override void Load()
        {
            var builder = new DbContextOptionsBuilder <ApplicationSettingsContext>();

            _setup(builder);

            using (var dbContext = new ApplicationSettingsContext(builder.Options))
            {
                dbContext.Database.EnsureCreated();
                Data = dbContext.Settings.Any()
                    ? dbContext.Settings.ToDictionary(it => it.Key, it => it.Value, StringComparer.OrdinalIgnoreCase)
                    : Initialize(dbContext);
            }
        }