// <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);
            }
        }
예제 #3
0
 internal ClonedPropertyValues(InternalPropertyValues original, DbDataRecord valuesRecord = null)
     : base(original.InternalContext, original.ObjectType, original.IsEntityValues)
 {
     this._propertyNames  = original.PropertyNames;
     this._propertyValues = (IDictionary <string, ClonedPropertyValuesItem>) new Dictionary <string, ClonedPropertyValuesItem>(this._propertyNames.Count);
     foreach (string propertyName in (IEnumerable <string>) this._propertyNames)
     {
         IPropertyValuesItem propertyValuesItem = original.GetItem(propertyName);
         object obj = propertyValuesItem.Value;
         InternalPropertyValues original1 = obj as InternalPropertyValues;
         if (original1 != null)
         {
             DbDataRecord valuesRecord1 = valuesRecord == null ? (DbDataRecord)null : (DbDataRecord)valuesRecord[propertyName];
             obj = (object)new ClonedPropertyValues(original1, valuesRecord1);
         }
         else if (valuesRecord != null)
         {
             obj = valuesRecord[propertyName];
             if (obj == DBNull.Value)
             {
                 obj = (object)null;
             }
         }
         this._propertyValues[propertyName] = new ClonedPropertyValuesItem(propertyName, obj, propertyValuesItem.Type, propertyValuesItem.IsComplex);
     }
 }
예제 #4
0
 public void SetValues(InternalPropertyValues values)
 {
     if (!this._type.IsAssignableFrom(values.ObjectType))
     {
         throw Error.DbPropertyValues_AttemptToSetValuesFromWrongType((object)values.ObjectType.Name, (object)this._type.Name);
     }
     foreach (string propertyName in (IEnumerable <string>) this.PropertyNames)
     {
         IPropertyValuesItem propertyValuesItem = values.GetItem(propertyName);
         if (propertyValuesItem.Value == null && propertyValuesItem.IsComplex)
         {
             throw Error.DbPropertyValues_NestedPropertyValuesNull((object)propertyName, (object)this._type.Name);
         }
         this[propertyName] = propertyValuesItem.Value;
     }
 }
        // <summary>
        // Appends a query for the properties in the entity to the given string builder that is being used to
        // build the eSQL query.  This method may be called recursively to query for all the sub-properties of
        // a complex property.
        // </summary>
        // <param name="queryBuilder"> The query builder. </param>
        // <param name="prefix"> The qualifier with which to prefix each property name. </param>
        // <param name="templateValues"> The dictionary that acts as a template for the properties to query. </param>
        private void AppendEntitySqlRow(
            StringBuilder queryBuilder, string prefix, InternalPropertyValues templateValues)
        {
            var commaRequired = false;

            foreach (var propertyName in templateValues.PropertyNames)
            {
                if (commaRequired)
                {
                    queryBuilder.Append(", ");
                }
                else
                {
                    commaRequired = true;
                }

                var quotedName = DbHelpers.QuoteIdentifier(propertyName);

                var templateItem = templateValues.GetItem(propertyName);

                if (templateItem.IsComplex)
                {
                    var nestedValues = templateItem.Value as InternalPropertyValues;
                    if (nestedValues == null)
                    {
                        throw Error.DbPropertyValues_CannotGetStoreValuesWhenComplexPropertyIsNull(
                                  propertyName, EntityType.Name);
                    }

                    // Call the same method recursively to get all the values of the complex property
                    queryBuilder.Append("ROW(");
                    AppendEntitySqlRow(
                        queryBuilder, String.Format(CultureInfo.InvariantCulture, "{0}.{1}", prefix, quotedName),
                        nestedValues);
                    queryBuilder.AppendFormat(CultureInfo.InvariantCulture, ") AS {0}", quotedName);
                }
                else
                {
                    queryBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}.{1} ", prefix, quotedName);
                }
            }
        }
        /// <summary>
        ///     Sets the values of this dictionary by reading values from another dictionary.
        ///     The other dictionary must be based on the same type as this dictionary, or a type derived
        ///     from the type for this dictionary.
        /// </summary>
        /// <param name="values"> The dictionary to read values from. </param>
        public void SetValues(InternalPropertyValues values)
        {
            DebugCheck.NotNull(values);

            // Setting values from a derived type is allowed, but setting values from a base type is not.
            if (!_type.IsAssignableFrom(values.ObjectType))
            {
                throw Error.DbPropertyValues_AttemptToSetValuesFromWrongType(values.ObjectType.Name, _type.Name);
            }

            foreach (var propertyName in PropertyNames)
            {
                var item = values.GetItem(propertyName);

                if (item.Value == null &&
                    item.IsComplex)
                {
                    throw Error.DbPropertyValues_NestedPropertyValuesNull(propertyName, _type.Name);
                }

                this[propertyName] = item.Value;
            }
        }
예제 #7
0
        private void AppendEntitySqlRow(
            StringBuilder queryBuilder,
            string prefix,
            InternalPropertyValues templateValues)
        {
            bool flag = false;

            foreach (string propertyName in (IEnumerable <string>)templateValues.PropertyNames)
            {
                if (flag)
                {
                    queryBuilder.Append(", ");
                }
                else
                {
                    flag = true;
                }
                string str = DbHelpers.QuoteIdentifier(propertyName);
                IPropertyValuesItem propertyValuesItem = templateValues.GetItem(propertyName);
                if (propertyValuesItem.IsComplex)
                {
                    InternalPropertyValues templateValues1 = propertyValuesItem.Value as InternalPropertyValues;
                    if (templateValues1 == null)
                    {
                        throw Error.DbPropertyValues_CannotGetStoreValuesWhenComplexPropertyIsNull((object)propertyName, (object)this.EntityType.Name);
                    }
                    queryBuilder.Append("ROW(");
                    this.AppendEntitySqlRow(queryBuilder, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}.{1}", (object)prefix, (object)str), templateValues1);
                    queryBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, ") AS {0}", (object)str);
                }
                else
                {
                    queryBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0}.{1} ", (object)prefix, (object)str);
                }
            }
        }
        /// <summary>
        ///     Appends a query for the properties in the entity to the given string builder that is being used to
        ///     build the eSQL query.  This method may be called recursively to query for all the sub-properties of
        ///     a complex property.
        /// </summary>
        /// <param name = "queryBuilder">The query builder.</param>
        /// <param name = "prefix">The qualifier with which to prefix each property name.</param>
        /// <param name = "templateValues">The dictionary that acts as a template for the properties to query.</param>
        private void AppendEntitySqlRow(
            StringBuilder queryBuilder, string prefix, InternalPropertyValues templateValues)
        {
            var commaRequired = false;
            foreach (var propertyName in templateValues.PropertyNames)
            {
                if (commaRequired)
                {
                    queryBuilder.Append(", ");
                }
                else
                {
                    commaRequired = true;
                }

                var quotedName = DbHelpers.QuoteIdentifier(propertyName);

                var templateItem = templateValues.GetItem(propertyName);

                if (templateItem.IsComplex)
                {
                    var nestedValues = templateItem.Value as InternalPropertyValues;
                    if (nestedValues == null)
                    {
                        throw Error.DbPropertyValues_CannotGetStoreValuesWhenComplexPropertyIsNull(
                            propertyName, EntityType.Name);
                    }

                    // Call the same method recursively to get all the values of the complex property
                    queryBuilder.Append("ROW(");
                    AppendEntitySqlRow(
                        queryBuilder, String.Format(CultureInfo.InvariantCulture, "{0}.{1}", prefix, quotedName),
                        nestedValues);
                    queryBuilder.AppendFormat(CultureInfo.InvariantCulture, ") AS {0}", quotedName);
                }
                else
                {
                    queryBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}.{1} ", prefix, quotedName);
                }
            }
        }
        // <summary>
        // Sets the values of this dictionary by reading values from another dictionary.
        // The other dictionary must be based on the same type as this dictionary, or a type derived
        // from the type for this dictionary.
        // </summary>
        // <param name="values"> The dictionary to read values from. </param>
        public void SetValues(InternalPropertyValues values)
        {
            DebugCheck.NotNull(values);

            // Setting values from a derived type is allowed, but setting values from a base type is not.
            if (!_type.IsAssignableFrom(values.ObjectType))
            {
                throw Error.DbPropertyValues_AttemptToSetValuesFromWrongType(values.ObjectType.Name, _type.Name);
            }

            foreach (var propertyName in PropertyNames)
            {
                var item = values.GetItem(propertyName);

                if (item.Value == null
                    && item.IsComplex)
                {
                    throw Error.DbPropertyValues_NestedPropertyValuesNull(propertyName, _type.Name);
                }

                this[propertyName] = item.Value;
            }
        }