private PropagatorResult CreateEntityKeyResult(
            IEntityStateEntry stateEntry,
            EntityKey entityKey)
        {
            RowType           keyRowType        = entityKey.GetEntitySet(this.m_translator.MetadataWorkspace).ElementType.GetKeyRowType();
            ExtractorMetadata extractorMetadata = this.m_translator.GetExtractorMetadata(stateEntry.EntitySet, (StructuralType)keyRowType);

            PropagatorResult[] values = new PropagatorResult[keyRowType.Properties.Count];
            for (int memberOffset = 0; memberOffset < keyRowType.Properties.Count; ++memberOffset)
            {
                EdmMember property = (EdmMember)keyRowType.Properties[memberOffset];
                ExtractorMetadata.MemberInformation member = extractorMetadata.m_memberMap[memberOffset];
                int    identifierForMemberOffset           = this.m_translator.KeyManager.GetKeyIdentifierForMemberOffset(entityKey, memberOffset, keyRowType.Properties.Count);
                object obj = !entityKey.IsTemporary ? entityKey.FindValueByName(property.Name) : stateEntry.StateManager.GetEntityStateEntry(entityKey).CurrentValues[property.Name];
                values[memberOffset] = PropagatorResult.CreateKeyValue(member.Flags, obj, stateEntry, identifierForMemberOffset);
            }
            return(PropagatorResult.CreateStructuralValue(values, extractorMetadata.m_type, false));
        }
        internal static PropagatorResult ExtractResultFromRecord(
            IEntityStateEntry stateEntry,
            bool isModified,
            IExtendedDataRecord record,
            bool useCurrentValues,
            UpdateTranslator translator,
            ModifiedPropertiesBehavior modifiedPropertiesBehavior)
        {
            StructuralType    edmType           = (StructuralType)record.DataRecordInfo.RecordType.EdmType;
            ExtractorMetadata extractorMetadata = translator.GetExtractorMetadata(stateEntry.EntitySet, edmType);
            EntityKey         entityKey         = stateEntry.EntityKey;

            PropagatorResult[] values = new PropagatorResult[record.FieldCount];
            for (int ordinal = 0; ordinal < values.Length; ++ordinal)
            {
                values[ordinal] = extractorMetadata.RetrieveMember(stateEntry, record, useCurrentValues, entityKey, ordinal, modifiedPropertiesBehavior);
            }
            return(PropagatorResult.CreateStructuralValue(values, edmType, isModified));
        }
예제 #3
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;
     }
 }
예제 #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;
            }
        }
        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));
        }