Пример #1
0
        private IEnumerable <DbModificationClause> BuildSetClauses(
            DbExpressionBinding target,
            PropagatorResult row,
            PropagatorResult originalRow,
            TableChangeProcessor processor,
            bool insertMode,
            out Dictionary <int, string> outputIdentifiers,
            out DbExpression returning,
            ref bool rowMustBeTouched)
        {
            Dictionary <EdmProperty, PropagatorResult>  dictionary       = new Dictionary <EdmProperty, PropagatorResult>();
            List <KeyValuePair <string, DbExpression> > keyValuePairList = new List <KeyValuePair <string, DbExpression> >();

            outputIdentifiers = new Dictionary <int, string>();
            PropagatorFlags propagatorFlags1 = insertMode ? PropagatorFlags.NoFlags : PropagatorFlags.Preserve | PropagatorFlags.Unknown;

            for (int index1 = 0; index1 < processor.Table.ElementType.Properties.Count; ++index1)
            {
                EdmProperty      property = processor.Table.ElementType.Properties[index1];
                PropagatorResult result   = row.GetMemberValue(index1);
                if (-1 != result.Identifier)
                {
                    result = result.ReplicateResultWithNewValue(this.m_translator.KeyManager.GetPrincipalValue(result));
                }
                bool flag1 = false;
                bool flag2 = false;
                for (int index2 = 0; index2 < processor.KeyOrdinals.Length; ++index2)
                {
                    if (processor.KeyOrdinals[index2] == index1)
                    {
                        flag2 = true;
                        break;
                    }
                }
                PropagatorFlags propagatorFlags2 = PropagatorFlags.NoFlags;
                if (!insertMode && flag2)
                {
                    flag1 = true;
                }
                else
                {
                    propagatorFlags2 |= result.PropagatorFlags;
                }
                StoreGeneratedPattern generatedPattern = MetadataHelper.GetStoreGeneratedPattern((EdmMember)property);
                bool flag3 = generatedPattern == StoreGeneratedPattern.Computed || insertMode && generatedPattern == StoreGeneratedPattern.Identity;
                if (flag3)
                {
                    DbPropertyExpression propertyExpression = target.Variable.Property(property);
                    keyValuePairList.Add(new KeyValuePair <string, DbExpression>(property.Name, (DbExpression)propertyExpression));
                    int identifier = result.Identifier;
                    if (-1 != identifier)
                    {
                        if (this.m_translator.KeyManager.HasPrincipals(identifier))
                        {
                            throw new InvalidOperationException(Strings.Update_GeneratedDependent((object)property.Name));
                        }
                        outputIdentifiers.Add(identifier, property.Name);
                        if (generatedPattern != StoreGeneratedPattern.Identity && processor.IsKeyProperty(index1))
                        {
                            throw new NotSupportedException(Strings.Update_NotSupportedComputedKeyColumn((object)"StoreGeneratedPattern", (object)"Computed", (object)"Identity", (object)property.Name, (object)property.DeclaringType.FullName));
                        }
                    }
                }
                if ((propagatorFlags2 & propagatorFlags1) != PropagatorFlags.NoFlags)
                {
                    flag1 = true;
                }
                else if (flag3)
                {
                    flag1            = true;
                    rowMustBeTouched = true;
                }
                if (!flag1 && !insertMode && generatedPattern == StoreGeneratedPattern.Identity)
                {
                    PropagatorResult memberValue = originalRow.GetMemberValue(index1);
                    if (!ByValueEqualityComparer.Default.Equals(memberValue.GetSimpleValue(), result.GetSimpleValue()))
                    {
                        throw new InvalidOperationException(Strings.Update_ModifyingIdentityColumn((object)"Identity", (object)property.Name, (object)property.DeclaringType.FullName));
                    }
                    flag1 = true;
                }
                if (!flag1)
                {
                    dictionary.Add(property, result);
                }
            }
            returning = 0 >= keyValuePairList.Count ? (DbExpression)null : (DbExpression)DbExpressionBuilder.NewRow((IEnumerable <KeyValuePair <string, DbExpression> >)keyValuePairList);
            List <DbModificationClause> modificationClauseList = new List <DbModificationClause>(dictionary.Count);

            foreach (KeyValuePair <EdmProperty, PropagatorResult> keyValuePair in dictionary)
            {
                EdmProperty key = keyValuePair.Key;
                modificationClauseList.Add((DbModificationClause) new DbSetClause(UpdateCompiler.GeneratePropertyExpression(target, keyValuePair.Key), this.GenerateValueExpression(keyValuePair.Key, keyValuePair.Value)));
            }
            return((IEnumerable <DbModificationClause>)modificationClauseList);
        }