/// <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)); }
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); } }