/// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(Object obj)
        {
            GenericEntity <TId> compareTo = obj as GenericEntity <TId>;

            if (ReferenceEquals(this, compareTo))
            {
                return(true);
            }

            if (compareTo == null || !GetType().Equals(compareTo.GetInnerType()))
            {
                return(false);
            }

            if (HasSameNonDefaultIdAs(compareTo))
            {
                return(true);
            }

            // Since the Ids aren't the same, both of them must be transient to compare domain signatures;
            // because if one is transient and the other is a persisted entity, then they cannot be the same object.
            return(IsTransient() && compareTo.IsTransient() && HasSameObjectSignatureAs(compareTo));
        }
 /// <summary>
 /// Determines whether self and the provided entity have the same Id values.
 /// </summary>
 /// <param name="compareTo">The compare to.</param>
 /// <returns>
 /// <c>true</c> if self and the provided entity have the same Id values; otherwise, <c>false</c>.
 /// </returns>
 private bool HasSameNonDefaultIdAs(GenericEntity <TId> compareTo)
 {
     return(!IsTransient() && !compareTo.IsTransient() && Id.Equals(compareTo.Id));
 }