/// <summary>
        ///     Sets the given value directly onto the underlying entity object.
        /// </summary>
        /// <param name="value"> The value. </param>
        /// <returns> True if the property had a setter that we could attempt to call; false if no setter was available. </returns>
        private bool SetCurrentValueOnClrObject(object value)
        {
            if (Setter == null)
            {
                return(false);
            }

            if (Getter == null ||
                !DbHelpers.KeyValuesEqual(value, Getter(InternalEntityEntry.Entity)))
            {
                Setter(InternalEntityEntry.Entity, value);
                if (EntryMetadata.IsMapped
                    &&
                    (InternalEntityEntry.State == EntityState.Modified ||
                     InternalEntityEntry.State == EntityState.Unchanged))
                {
                    IsModified = true;
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        ///     Sets the value of the property only if it is different from the current value and is not
        ///     an invalid attempt to set a complex property.
        /// </summary>
        private void SetValue(IPropertyValuesItem item, object newValue)
        {
            // Using KeyValuesEqual here to control setting the property to modified since the deep
            // comparison of binary values is more appropriate for all properties when used in an
            // N-Tier or concurrency situation.
            if (!DbHelpers.KeyValuesEqual(item.Value, newValue))
            {
                if (item.Value == null &&
                    item.IsComplex)
                {
                    throw Error.DbPropertyValues_NestedPropertyValuesNull(item.Name, _type.Name);
                }

                if (newValue != null &&
                    !item.Type.IsAssignableFrom(newValue.GetType()))
                {
                    throw Error.DbPropertyValues_WrongTypeForAssignment(
                              newValue.GetType().Name, item.Name, item.Type.Name, _type.Name);
                }

                item.Value = newValue;
            }
        }
        public void KeyValuesEqual_checks_value_equality_for_value_types_and_Equals_implementation_for_reference_types()
        {
            Equality_tests(DbHelpers.KeyValuesEqual);

            Assert.True(DbHelpers.KeyValuesEqual(new ExecutionStrategyKey("foo", "bar"), new ExecutionStrategyKey("foo", "bar")));
        }