Exemple #1
0
        public void SetValues(object value)
        {
            IDictionary <string, Func <object, object> > propertyGetters = DbHelpers.GetPropertyGetters(value.GetType());

            foreach (string propertyName in (IEnumerable <string>) this.PropertyNames)
            {
                Func <object, object> func;
                if (propertyGetters.TryGetValue(propertyName, out func))
                {
                    object newValue = func(value);
                    IPropertyValuesItem propertyValuesItem = this.GetItem(propertyName);
                    if (newValue == null && propertyValuesItem.IsComplex)
                    {
                        throw Error.DbPropertyValues_ComplexObjectCannotBeNull((object)propertyName, (object)this._type.Name);
                    }
                    InternalPropertyValues internalPropertyValues = propertyValuesItem.Value as InternalPropertyValues;
                    if (internalPropertyValues == null)
                    {
                        this.SetValue(propertyValuesItem, newValue);
                    }
                    else
                    {
                        internalPropertyValues.SetValues(newValue);
                    }
                }
            }
        }
Exemple #2
0
 public object this[string propertyName]
 {
     get
     {
         return(this.GetItem(propertyName).Value);
     }
     set
     {
         DbPropertyValues dbPropertyValues = value as DbPropertyValues;
         if (dbPropertyValues != null)
         {
             value = (object)dbPropertyValues.InternalPropertyValues;
         }
         IPropertyValuesItem    propertyValuesItem     = this.GetItem(propertyName);
         InternalPropertyValues internalPropertyValues = propertyValuesItem.Value as InternalPropertyValues;
         if (internalPropertyValues == null)
         {
             this.SetValue(propertyValuesItem, value);
         }
         else
         {
             InternalPropertyValues values = value as InternalPropertyValues;
             if (values == null)
             {
                 throw Error.DbPropertyValues_AttemptToSetNonValuesOnComplexProperty();
             }
             internalPropertyValues.SetValues(values);
         }
     }
 }
Exemple #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);
     }
 }
Exemple #4
0
 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;
 }
Exemple #5
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>
        ///     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;
            }
        }
Exemple #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>
        // 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;
            }
        }