/// <summary> /// Returns true if self and the provided entity have the same Id values /// and the Ids are not of the default Id value /// </summary> protected bool HasSameNonDefaultIdAs(Preference compareTo) { return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id)); }
/// <summary> /// Copies the current object to a new instance /// </summary> /// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param> /// <param name="copiedObjects">Objects that should be reused</param> /// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param> /// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param> /// <param name="copy">Optional - An existing [Preference] instance to use as the destination.</param> /// <returns>A copy of the object</returns> public virtual Preference Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, Preference copy = null) { if (copiedObjects == null) { copiedObjects = new Hashtable(); } if (copy == null && copiedObjects.Contains(this)) { return((Preference)copiedObjects[this]); } copy = copy ?? new Preference(); if (!asNew) { copy.TransientId = this.TransientId; copy.Id = this.Id; } copy.PreferenceValue = this.PreferenceValue; if (!copiedObjects.Contains(this)) { copiedObjects.Add(this, copy); } if (deep && this.preferenceType != null) { if (!copiedObjects.Contains(this.preferenceType)) { if (asNew && reuseNestedObjects) { copy.PreferenceType = this.PreferenceType; } else if (asNew) { copy.PreferenceType = this.PreferenceType.Copy(deep, copiedObjects, true); } else { copy.preferenceType = this.preferenceType.Copy(deep, copiedObjects, false); } } else { if (asNew) { copy.PreferenceType = (PreferenceType)copiedObjects[this.PreferenceType]; } else { copy.preferenceType = (PreferenceType)copiedObjects[this.PreferenceType]; } } } return(copy); }