protected override void SetRecordValue(int ordinal, object value)
        {
            StateManagerMemberMetadata managerMemberMetadata = this._metadata.Member(ordinal);

            if (managerMemberMetadata.IsComplex)
            {
                throw new InvalidOperationException(Strings.ObjectStateEntry_SetOriginalComplexProperties((object)managerMemberMetadata.CLayerName));
            }
            object      newFieldValue = value ?? (object)DBNull.Value;
            EntityEntry cacheEntry    = this._cacheEntry as EntityEntry;
            EntityState state         = cacheEntry.State;

            if (!cacheEntry.HasRecordValueChanged((DbDataRecord)this, ordinal, newFieldValue))
            {
                return;
            }
            if (managerMemberMetadata.IsPartOfKey)
            {
                throw new InvalidOperationException(Strings.ObjectStateEntry_SetOriginalPrimaryKey((object)managerMemberMetadata.CLayerName));
            }
            Type clrType = managerMemberMetadata.ClrType;

            if (DBNull.Value == newFieldValue && clrType.IsValueType() && !managerMemberMetadata.CdmMetadata.Nullable)
            {
                throw new InvalidOperationException(Strings.ObjectStateEntry_NullOriginalValueForNonNullableProperty((object)managerMemberMetadata.CLayerName, (object)managerMemberMetadata.ClrMetadata.Name, (object)managerMemberMetadata.ClrMetadata.DeclaringType.FullName));
            }
            base.SetRecordValue(ordinal, value);
            if (state == EntityState.Unchanged && cacheEntry.State == EntityState.Modified)
            {
                cacheEntry.ObjectStateManager.ChangeState(cacheEntry, state, EntityState.Modified);
            }
            cacheEntry.SetModifiedPropertyInternal(this.GetPropertyIndex(ordinal));
        }
        protected override void SetRecordValue(int ordinal, object value)
        {
            StateManagerMemberMetadata member = _metadata.Member(ordinal);

            // We do not allow setting complex properties through writeable original values.
            // Instead individual scalar properties can be set on a data record that represents the complex type.
            if (member.IsComplex)
            {
                throw EntityUtil.SetOriginalComplexProperties(member.CLayerName);
            }

            // Null values are represented in data records as DBNull.Value, so translate appropriately
            object fieldValue = value ?? DBNull.Value;

            EntityEntry entry    = _cacheEntry as EntityEntry;
            EntityState oldState = entry.State;

            // Only update the original values if the new value is different from the value currently set on the entity
            if (entry.HasRecordValueChanged(this, ordinal, fieldValue))
            {
                // Since the original value is going to be set, validate that is doesn't violate any restrictions

                // Throw if trying to change the original value of the primary key
                if (member.IsPartOfKey)
                {
                    throw EntityUtil.SetOriginalPrimaryKey(member.CLayerName);
                }

                // Verify non-nullable EDM members are not being set to null
                // Need to continue allowing CLR reference types to be set to null for backwards compatibility
                Type memberClrType = member.ClrType;
                if ((object)DBNull.Value == fieldValue &&
                    memberClrType.IsValueType &&
                    !member.CdmMetadata.Nullable)
                {
                    // Throw if the underlying CLR type of this property is not nullable, and it is being set to null
                    throw EntityUtil.NullOriginalValueForNonNullableProperty(member.CLayerName, member.ClrMetadata.Name, member.ClrMetadata.DeclaringType.FullName);
                }

                base.SetRecordValue(ordinal, value);

                // Update the state of the ObjectStateEntry if it has been marked as Modified
                if (oldState == EntityState.Unchanged && entry.State == EntityState.Modified)
                {
                    entry.ObjectStateManager.ChangeState(entry, oldState, EntityState.Modified);
                }

                // Set the individual property to modified
                entry.SetModifiedPropertyInternal(GetPropertyIndex(ordinal));
            }
        }