private void SetValue(IPropertyValuesItem item, object newValue) { if (DbHelpers.PropertyValuesEqual(item.Value, newValue)) { return; } if (item.Value == null && item.IsComplex) { throw Error.DbPropertyValues_NestedPropertyValuesNull((object)item.Name, (object)this._type.Name); } if (newValue != null && !item.Type.IsAssignableFrom(newValue.GetType())) { throw Error.DbPropertyValues_WrongTypeForAssignment((object)newValue.GetType().Name, (object)item.Name, (object)item.Type.Name, (object)this._type.Name); } item.Value = newValue; }
private bool SetCurrentValueOnClrObject(object value) { if (this.Setter == null) { return(false); } if (this.Getter == null || !DbHelpers.PropertyValuesEqual(value, this.Getter(this.InternalEntityEntry.Entity))) { this.Setter(this.InternalEntityEntry.Entity, value); if (this.EntryMetadata.IsMapped && (this.InternalEntityEntry.State == EntityState.Modified || this.InternalEntityEntry.State == EntityState.Unchanged)) { this.IsModified = true; } } return(true); }
/// <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.PropertyValuesEqual(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 PropertyValuesEqual_checks_value_equality_for_value_types_and_reference_equality_for_reference_types() { Equality_tests(DbHelpers.PropertyValuesEqual); Assert.False(DbHelpers.PropertyValuesEqual(new ExecutionStrategyKey("foo", "bar"), new ExecutionStrategyKey("foo", "bar"))); }