public string GetValue(string name) { using (ZSZDbContext context = new ZSZDbContext()) { BaseService <SettingEntity> service = new BaseService <SettingEntity>(context); SettingEntity entity = service.GetAll().AsNoTracking().SingleOrDefault(p => p.Name == name); return(entity == null ? null : entity.Value); } }
public void SetValue(string name, string value) { using (ZSZDbContext context = new ZSZDbContext()) { BaseService <SettingEntity> service = new BaseService <SettingEntity>(context); SettingEntity entity = service.GetAll().SingleOrDefault(p => p.Name == name); if (entity == null) { context.Settings.Add(new SettingEntity { Name = name, Value = value }); } else { entity.Value = value; } context.SaveChanges(); } }