// <summary>
        // Initializes a new instance of the <see cref="ClonedPropertyValues" /> class by copying
        // values from the given dictionary.
        // </summary>
        // <param name="original"> The dictionary to clone. </param>
        // <param name="valuesRecord"> If non-null, then the values for the new dictionary are taken from this record rather than from the original dictionary. </param>
        internal ClonedPropertyValues(InternalPropertyValues original, DbDataRecord valuesRecord = null)
            : base(original.InternalContext, original.ObjectType, original.IsEntityValues)
        {
            _propertyNames  = original.PropertyNames;
            _propertyValues = new Dictionary <string, ClonedPropertyValuesItem>(_propertyNames.Count);

            foreach (var propertyName in _propertyNames)
            {
                var item = original.GetItem(propertyName);

                var value    = item.Value;
                var asValues = value as InternalPropertyValues;
                if (asValues != null)
                {
                    var nestedValuesRecord = valuesRecord == null ? null : (DbDataRecord)valuesRecord[propertyName];
                    value = new ClonedPropertyValues(asValues, nestedValuesRecord);
                }
                else if (valuesRecord != null)
                {
                    value = valuesRecord[propertyName];
                    if (value == DBNull.Value)
                    {
                        value = null;
                    }
                }

                _propertyValues[propertyName] = new ClonedPropertyValuesItem(
                    propertyName, value, item.Type, item.IsComplex);
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref = "ClonedPropertyValues" /> class by copying
        ///     values from the given dictionary.
        /// </summary>
        /// <param name = "original">The dictionary to clone.</param>
        /// <param name = "valuesRecord">If non-null, then the values for the new dictionary are taken from this record rather than from the original dictionary.</param>
        internal ClonedPropertyValues(InternalPropertyValues original, DbDataRecord valuesRecord = null)
            : base(original.InternalContext, original.ObjectType, original.IsEntityValues)
        {
            _propertyNames = original.PropertyNames;
            _propertyValues = new Dictionary<string, ClonedPropertyValuesItem>(_propertyNames.Count);

            foreach (var propertyName in _propertyNames)
            {
                var item = original.GetItem(propertyName);

                var value = item.Value;
                var asValues = value as InternalPropertyValues;
                if (asValues != null)
                {
                    var nestedValuesRecord = valuesRecord == null ? null : (DbDataRecord)valuesRecord[propertyName];
                    value = new ClonedPropertyValues(asValues, nestedValuesRecord);
                }
                else if (valuesRecord != null)
                {
                    value = valuesRecord[propertyName];
                    if (value == DBNull.Value)
                    {
                        value = null;
                    }
                }

                _propertyValues[propertyName] = new ClonedPropertyValuesItem(
                    propertyName, value, item.Type, item.IsComplex);
            }
        }