예제 #1
0
        // <summary>
        // Converts a record to a propagator result
        // </summary>
        // <param name="stateEntry"> state manager entry containing the record </param>
        // <param name="isModified"> Indicates whether the root element is modified (i.e., whether the type has changed) </param>
        // <param name="record"> Record to convert </param>
        // <param name="useCurrentValues"> Indicates whether we are retrieving current or original values. </param>
        // <param name="translator"> Translator for session context; registers new metadata for the record type if none exists </param>
        // <param name="modifiedPropertiesBehavior"> Indicates how to determine whether a property is modified. </param>
        // <returns> Result corresponding to the given record </returns>
        internal static PropagatorResult ExtractResultFromRecord(
            IEntityStateEntry stateEntry, bool isModified, IExtendedDataRecord record,
            bool useCurrentValues, UpdateTranslator translator, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            var structuralType = (StructuralType)record.DataRecordInfo.RecordType.EdmType;
            var metadata       = translator.GetExtractorMetadata(stateEntry.EntitySet, structuralType);
            var key            = stateEntry.EntityKey;

            var nestedValues = new PropagatorResult[record.FieldCount];

            for (var ordinal = 0; ordinal < nestedValues.Length; ordinal++)
            {
                nestedValues[ordinal] = metadata.RetrieveMember(
                    stateEntry, record, useCurrentValues, key,
                    ordinal, modifiedPropertiesBehavior);
            }

            return(PropagatorResult.CreateStructuralValue(nestedValues, structuralType, isModified));
        }
예제 #2
0
 private PropagatorResult ConvertStateEntryToPropagatorResult(
     IEntityStateEntry stateEntry,
     bool useCurrentValues,
     ModifiedPropertiesBehavior modifiedPropertiesBehavior)
 {
     try
     {
         IExtendedDataRecord record = useCurrentValues ? (IExtendedDataRecord)stateEntry.CurrentValues : (IExtendedDataRecord)stateEntry.OriginalValues;
         bool isModified            = false;
         return(ExtractorMetadata.ExtractResultFromRecord(stateEntry, isModified, record, useCurrentValues, this.m_updateTranslator, modifiedPropertiesBehavior));
     }
     catch (Exception ex)
     {
         if (ex.RequiresContext())
         {
             throw EntityUtil.Update(Strings.Update_ErrorLoadingRecord, ex, stateEntry);
         }
         throw;
     }
 }
        private PropagatorResult ConvertStateEntryToPropagatorResult(IEntityStateEntry stateEntry, bool useCurrentValues, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            try
            {
                EntityUtil.CheckArgumentNull(stateEntry, "stateEntry");
                IExtendedDataRecord record = useCurrentValues
                    ? EntityUtil.CheckArgumentNull(stateEntry.CurrentValues as IExtendedDataRecord, "stateEntry.CurrentValues")
                    : EntityUtil.CheckArgumentNull(stateEntry.OriginalValues as IExtendedDataRecord, "stateEntry.OriginalValues");

                bool isModified = false; // the root of the state entry is unchanged because the type is static
                return ExtractorMetadata.ExtractResultFromRecord(stateEntry, isModified, record, useCurrentValues, m_updateTranslator, modifiedPropertiesBehavior);
            }
            catch (Exception e)
            {
                if (UpdateTranslator.RequiresContext(e))
                {
                    throw EntityUtil.Update(Strings.Update_ErrorLoadingRecord, e, stateEntry);
                }
                throw;
            }
        }
예제 #4
0
        private PropagatorResult ConvertStateEntryToPropagatorResult(
            IEntityStateEntry stateEntry, bool useCurrentValues, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            DebugCheck.NotNull(stateEntry);

            try
            {
                var record = useCurrentValues
                                 ? stateEntry.CurrentValues
                                 : (IExtendedDataRecord)stateEntry.OriginalValues;

                var isModified = false; // the root of the state entry is unchanged because the type is static
                return(ExtractorMetadata.ExtractResultFromRecord(
                           stateEntry, isModified, record, useCurrentValues, m_updateTranslator, modifiedPropertiesBehavior));
            }
            catch (Exception e)
            {
                if (e.RequiresContext())
                {
                    throw EntityUtil.Update(Strings.Update_ErrorLoadingRecord, e, stateEntry);
                }
                throw;
            }
        }
        private PropagatorResult ConvertStateEntryToPropagatorResult(
            IEntityStateEntry stateEntry, bool useCurrentValues, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            Contract.Requires(stateEntry != null);

            try
            {
                var record = useCurrentValues
                                 ? stateEntry.CurrentValues
                                 : (IExtendedDataRecord)stateEntry.OriginalValues;

                var isModified = false; // the root of the state entry is unchanged because the type is static
                return ExtractorMetadata.ExtractResultFromRecord(
                    stateEntry, isModified, record, useCurrentValues, m_updateTranslator, modifiedPropertiesBehavior);
            }
            catch (Exception e)
            {
                if (e.RequiresContext())
                {
                    throw EntityUtil.Update(Strings.Update_ErrorLoadingRecord, e, stateEntry);
                }
                throw;
            }
        }
예제 #6
0
        // <summary>
        // Requires: record must have correct type for this metadata instance.
        // Populates a new <see cref="PropagatorResult" /> object representing a member of a record matching the
        // type of this extractor. Given a record and a member, this method wraps the value of the member
        // in a PropagatorResult. This operation can be performed efficiently by this class, which knows
        // important stuff about the type being extracted.
        // </summary>
        // <param name="stateEntry"> state manager entry containing value (used for error reporting) </param>
        // <param name="record"> Record containing value (used to find the actual value) </param>
        // <param name="useCurrentValues"> Indicates whether we are reading current or original values. </param>
        // <param name="key"> Entity key for the state entry. Must be set for entity records. </param>
        // <param name="ordinal"> Ordinal of Member for which to retrieve a value. </param>
        // <param name="modifiedPropertiesBehavior"> Indicates how to determine whether a property is modified. </param>
        // <returns> Propagator result describing this member value. </returns>
        internal PropagatorResult RetrieveMember(
            IEntityStateEntry stateEntry, IExtendedDataRecord record, bool useCurrentValues,
            EntityKey key, int ordinal, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            var memberInformation = m_memberMap[ordinal];

            // get identifier value
            int identifier;

            if (memberInformation.IsKeyMember)
            {
                // retrieve identifier for this key member
                Debug.Assert(
                    null != (object)key, "entities must have keys, and only entity members are marked IsKeyMember by " +
                    "the metadata wrapper");
                var keyOrdinal = memberInformation.EntityKeyOrdinal.Value;
                identifier = m_translator.KeyManager.GetKeyIdentifierForMemberOffset(key, keyOrdinal, ((EntityType)m_type).KeyMembers.Count);
            }
            else if (memberInformation.IsForeignKeyMember)
            {
                identifier = m_translator.KeyManager.GetKeyIdentifierForMember(key, record.GetName(ordinal), useCurrentValues);
            }
            else
            {
                identifier = PropagatorResult.NullIdentifier;
            }

            // determine if the member is modified
            var isModified = modifiedPropertiesBehavior == ModifiedPropertiesBehavior.AllModified ||
                             (modifiedPropertiesBehavior == ModifiedPropertiesBehavior.SomeModified &&
                              stateEntry.ModifiedProperties != null &&
                              stateEntry.ModifiedProperties[memberInformation.Ordinal]);

            // determine member value
            Debug.Assert(record.GetName(ordinal) == memberInformation.Member.Name, "expect record to present properties in metadata order");
            if (memberInformation.CheckIsNotNull &&
                record.IsDBNull(ordinal))
            {
                throw EntityUtil.Update(Strings.Update_NullValue(record.GetName(ordinal)), null, stateEntry);
            }
            var value = record.GetValue(ordinal);

            // determine what kind of member this is

            // entityKey (association end)
            var entityKey = value as EntityKey;

            if (null != (object)entityKey)
            {
                return(CreateEntityKeyResult(stateEntry, entityKey));
            }

            // record (nested complex type)
            var nestedRecord = value as IExtendedDataRecord;

            if (null != nestedRecord)
            {
                // for structural types, we track whether the entire complex type value is modified or not
                var nestedModifiedPropertiesBehavior = isModified
                                                           ? ModifiedPropertiesBehavior.AllModified
                                                           : ModifiedPropertiesBehavior.NoneModified;
                var translator = m_translator;

                return(ExtractResultFromRecord(
                           stateEntry, isModified, nestedRecord, useCurrentValues, translator, nestedModifiedPropertiesBehavior));
            }

            // simple value (column/property value)
            return(CreateSimpleResult(stateEntry, record, memberInformation, identifier, isModified, ordinal, value));
        }
 /// <summary>
 /// Converts current values in a state entry to a DbNewInstanceExpression. The record must be either an entity or
 /// a relationship set instance.
 /// </summary>
 /// <remarks>
 /// This method is not thread safe.
 /// </remarks>
 /// <param name="stateEntry">Gets state entry this record is associated with.</param>
 /// <param name="modifiedPropertiesBehavior">Indicates how to determine whether a property is modified.</param>
 /// <returns>New instance expression.</returns>
 internal PropagatorResult ConvertCurrentValuesToPropagatorResult(IEntityStateEntry stateEntry, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
 {
     return(ConvertStateEntryToPropagatorResult(stateEntry, useCurrentValues: true, modifiedPropertiesBehavior: modifiedPropertiesBehavior));
 }
 /// <summary>
 /// Converts current values in a state entry to a DbNewInstanceExpression. The record must be either an entity or 
 /// a relationship set instance.
 /// </summary>
 /// <remarks>
 /// This method is not thread safe.
 /// </remarks>
 /// <param name="stateEntry">Gets state entry this record is associated with.</param>
 /// <param name="modifiedPropertiesBehavior">Indicates how to determine whether a property is modified.</param>
 /// <returns>New instance expression.</returns>
 internal PropagatorResult ConvertCurrentValuesToPropagatorResult(IEntityStateEntry stateEntry, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
 {
     return ConvertStateEntryToPropagatorResult(stateEntry, useCurrentValues: true, modifiedPropertiesBehavior: modifiedPropertiesBehavior);
 }
        /// <summary>
        /// Converts a record to a propagator result
        /// </summary>
        /// <param name="stateEntry">state manager entry containing the record</param>
        /// <param name="isModified">Indicates whether the root element is modified (i.e., whether the type has changed)</param>
        /// <param name="record">Record to convert</param>
        /// <param name="useCurrentValues">Indicates whether we are retrieving current or original values.</param>
        /// <param name="translator">Translator for session context; registers new metadata for the record type if none
        /// exists</param>
        /// <param name="modifiedPropertiesBehavior">Indicates how to determine whether a property is modified.</param>
        /// <returns>Result corresponding to the given record</returns>
        internal static PropagatorResult ExtractResultFromRecord(
            IEntityStateEntry stateEntry, bool isModified, IExtendedDataRecord record,
            bool useCurrentValues, UpdateTranslator translator, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            var structuralType = (StructuralType)record.DataRecordInfo.RecordType.EdmType;
            var metadata = translator.GetExtractorMetadata(stateEntry.EntitySet, structuralType);
            var key = stateEntry.EntityKey;

            var nestedValues = new PropagatorResult[record.FieldCount];
            for (var ordinal = 0; ordinal < nestedValues.Length; ordinal++)
            {
                nestedValues[ordinal] = metadata.RetrieveMember(
                    stateEntry, record, useCurrentValues, key,
                    ordinal, modifiedPropertiesBehavior);
            }

            return PropagatorResult.CreateStructuralValue(nestedValues, structuralType, isModified);
        }
        /// <summary>
        /// Requires: record must have correct type for this metadata instance.
        /// Populates a new <see cref="PropagatorResult"/> object representing a member of a record matching the 
        /// type of this extractor. Given a record and a member, this method wraps the value of the member
        /// in a PropagatorResult. This operation can be performed efficiently by this class, which knows
        /// important stuff about the type being extracted.
        /// </summary>
        /// <param name="stateEntry">state manager entry containing value (used for error reporting)</param>
        /// <param name="record">Record containing value (used to find the actual value)</param>
        /// <param name="currentValues">Indicates whether we are reading current or original values.</param>
        /// <param name="key">Entity key for the state entry. Must be set for entity records.</param>
        /// <param name="ordinal">Ordinal of Member for which to retrieve a value.</param>
        /// modified (must be ordinally aligned with the type). Null indicates all members are modified.</param>
        /// <param name="modifiedPropertiesBehavior">Indicates how to determine whether a property is modified.</param>
        /// <returns>Propagator result describing this member value.</returns>
        internal PropagatorResult RetrieveMember(
            IEntityStateEntry stateEntry, IExtendedDataRecord record, bool useCurrentValues,
            EntityKey key, int ordinal, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            var memberInformation = m_memberMap[ordinal];

            // get identifier value
            int identifier;
            if (memberInformation.IsKeyMember)
            {
                // retrieve identifier for this key member
                Debug.Assert(
                    null != (object)key, "entities must have keys, and only entity members are marked IsKeyMember by " +
                                         "the metadata wrapper");
                var keyOrdinal = memberInformation.EntityKeyOrdinal.Value;
                identifier = m_translator.KeyManager.GetKeyIdentifierForMemberOffset(key, keyOrdinal, ((EntityType)m_type).KeyMembers.Count);
            }
            else if (memberInformation.IsForeignKeyMember)
            {
                identifier = m_translator.KeyManager.GetKeyIdentifierForMember(key, record.GetName(ordinal), useCurrentValues);
            }
            else
            {
                identifier = PropagatorResult.NullIdentifier;
            }

            // determine if the member is modified
            var isModified = modifiedPropertiesBehavior == ModifiedPropertiesBehavior.AllModified ||
                             (modifiedPropertiesBehavior == ModifiedPropertiesBehavior.SomeModified &&
                              stateEntry.ModifiedProperties != null &&
                              stateEntry.ModifiedProperties[memberInformation.Ordinal]);

            // determine member value
            Debug.Assert(record.GetName(ordinal) == memberInformation.Member.Name, "expect record to present properties in metadata order");
            if (memberInformation.CheckIsNotNull
                && record.IsDBNull(ordinal))
            {
                throw EntityUtil.Update(Strings.Update_NullValue(record.GetName(ordinal)), null, stateEntry);
            }
            var value = record.GetValue(ordinal);

            // determine what kind of member this is

            // entityKey (association end)
            var entityKey = value as EntityKey;
            if (null != (object)entityKey)
            {
                return CreateEntityKeyResult(stateEntry, entityKey);
            }

            // record (nested complex type)
            var nestedRecord = value as IExtendedDataRecord;
            if (null != nestedRecord)
            {
                // for structural types, we track whether the entire complex type value is modified or not
                var nestedModifiedPropertiesBehavior = isModified
                                                           ? ModifiedPropertiesBehavior.AllModified
                                                           : ModifiedPropertiesBehavior.NoneModified;
                var translator = m_translator;

                return ExtractResultFromRecord(
                    stateEntry, isModified, nestedRecord, useCurrentValues, translator, nestedModifiedPropertiesBehavior);
            }

            // simple value (column/property value)
            return CreateSimpleResult(stateEntry, record, memberInformation, identifier, isModified, ordinal, value);
        }
예제 #11
0
 internal PropagatorResult ConvertOriginalValuesToPropagatorResult(
     IEntityStateEntry stateEntry,
     ModifiedPropertiesBehavior modifiedPropertiesBehavior)
 {
     return(this.ConvertStateEntryToPropagatorResult(stateEntry, false, modifiedPropertiesBehavior));
 }
        internal PropagatorResult RetrieveMember(
            IEntityStateEntry stateEntry,
            IExtendedDataRecord record,
            bool useCurrentValues,
            EntityKey key,
            int ordinal,
            ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            ExtractorMetadata.MemberInformation member = this.m_memberMap[ordinal];
            int identifier;

            if (member.IsKeyMember)
            {
                int memberOffset = member.EntityKeyOrdinal.Value;
                identifier = this.m_translator.KeyManager.GetKeyIdentifierForMemberOffset(key, memberOffset, ((EntityTypeBase)this.m_type).KeyMembers.Count);
            }
            else
            {
                identifier = !member.IsForeignKeyMember ? -1 : this.m_translator.KeyManager.GetKeyIdentifierForMember(key, record.GetName(ordinal), useCurrentValues);
            }
            int num;

            switch (modifiedPropertiesBehavior)
            {
            case ModifiedPropertiesBehavior.AllModified:
                num = 1;
                break;

            case ModifiedPropertiesBehavior.SomeModified:
                if (stateEntry.ModifiedProperties != null)
                {
                    num = stateEntry.ModifiedProperties[member.Ordinal] ? 1 : 0;
                    break;
                }
                goto default;

            default:
                num = 0;
                break;
            }
            bool isModified = num != 0;

            if (member.CheckIsNotNull && record.IsDBNull(ordinal))
            {
                throw EntityUtil.Update(Strings.Update_NullValue((object)record.GetName(ordinal)), (Exception)null, stateEntry);
            }
            object    obj       = record.GetValue(ordinal);
            EntityKey entityKey = obj as EntityKey;

            if ((object)entityKey != null)
            {
                return(this.CreateEntityKeyResult(stateEntry, entityKey));
            }
            IExtendedDataRecord record1 = obj as IExtendedDataRecord;

            if (record1 == null)
            {
                return(this.CreateSimpleResult(stateEntry, record, member, identifier, isModified, ordinal, obj));
            }
            ModifiedPropertiesBehavior modifiedPropertiesBehavior1 = isModified ? ModifiedPropertiesBehavior.AllModified : ModifiedPropertiesBehavior.NoneModified;
            UpdateTranslator           translator = this.m_translator;

            return(ExtractorMetadata.ExtractResultFromRecord(stateEntry, isModified, record1, useCurrentValues, translator, modifiedPropertiesBehavior1));
        }