public static void SetUserSetting(string key, string value) { UserSetting userSetting = Context.UserSetting.FirstOrDefault(obj => obj.Key == key); bool isExists = userSetting != null; if (!isExists) { userSetting = new UserSetting(); userSetting.Key = key; userSetting.Value = value; Context.UserSetting.AddObject(userSetting); } else { userSetting.Value = value; } Context.SaveChanges(); }
/// <summary> /// 创建新的 UserSetting 对象。 /// </summary> /// <param name="key">Key 属性的初始值。</param> public static UserSetting CreateUserSetting(global::System.String key) { UserSetting userSetting = new UserSetting(); userSetting.Key = key; return userSetting; }
/// <summary> /// 用于向 UserSetting EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToUserSetting(UserSetting userSetting) { base.AddObject("UserSetting", userSetting); }