internal object GetPrincipalValue(PropagatorResult result)
        {
            int identifier = result.Identifier;

            if (-1 == identifier)
            {
                return(result.GetSimpleValue());
            }
            bool   flag = true;
            object x    = (object)null;

            foreach (int principal in this.GetPrincipals(identifier))
            {
                PropagatorResult owner = this._identifiers[principal].Owner;
                if (owner != null)
                {
                    if (flag)
                    {
                        x    = owner.GetSimpleValue();
                        flag = false;
                    }
                    else if (!ByValueEqualityComparer.Default.Equals(x, owner.GetSimpleValue()))
                    {
                        throw new ConstraintException(Strings.Update_ReferentialConstraintIntegrityViolation);
                    }
                }
            }
            if (flag)
            {
                x = result.GetSimpleValue();
            }
            return(x);
        }
 private int GetComponentHashCode(PropagatorResult keyComponent)
 {
     if (keyComponent.Identifier == -1)
     {
         return(ByValueEqualityComparer.Default.GetHashCode(keyComponent.GetSimpleValue()));
     }
     return(this._manager.GetCliqueIdentifier(keyComponent.Identifier).GetHashCode());
 }
Ejemplo n.º 3
0
        // <summary>
        // Given a value, returns the value for its principal owner.
        // </summary>
        internal object GetPrincipalValue(PropagatorResult result)
        {
            var currentIdentifier = result.Identifier;

            if (PropagatorResult.NullIdentifier == currentIdentifier)
            {
                // for non-identifiers, there is nothing to resolve
                return(result.GetSimpleValue());
            }

            // find principals for this value
            var    first = true;
            object value = null;

            foreach (var principal in GetPrincipals(currentIdentifier))
            {
                var ownerResult = _identifiers[principal].Owner;
                if (null != ownerResult)
                {
                    if (first)
                    {
                        // result is taken from the first principal
                        value = ownerResult.GetSimpleValue();
                        first = false;
                    }
                    else
                    {
                        // subsequent results are validated for consistency with the first
                        if (!ByValueEqualityComparer.Default.Equals(value, ownerResult.GetSimpleValue()))
                        {
                            throw new ConstraintException(Strings.Update_ReferentialConstraintIntegrityViolation);
                        }
                    }
                }
            }

            if (first)
            {
                // if there are no principals, return the current value directly
                value = result.GetSimpleValue();
            }
            return(value);
        }
Ejemplo n.º 4
0
 // Gets the value to use for hash code
 private int GetComponentHashCode(PropagatorResult keyComponent)
 {
     if (keyComponent.Identifier
         == PropagatorResult.NullIdentifier)
     {
         // no identifier exists for this key component, so use the actual key
         // value
         Debug.Assert(
             null != keyComponent && null != keyComponent,
             "key value must not be null");
         return(ByValueEqualityComparer.Default.GetHashCode(keyComponent.GetSimpleValue()));
     }
     else
     {
         // use ID for FK graph clique (this ensures that keys fixed up to the same
         // value based on a constraint will have the same hash code)
         return(_manager.GetCliqueIdentifier(keyComponent.Identifier).GetHashCode());
     }
 }
 public bool Equals(CompositeKey left, CompositeKey right)
 {
     if (object.ReferenceEquals((object)left, (object)right))
     {
         return(true);
     }
     if (left == null || right == null || left.KeyComponents.Length != right.KeyComponents.Length)
     {
         return(false);
     }
     for (int index = 0; index < left.KeyComponents.Length; ++index)
     {
         PropagatorResult keyComponent1 = left.KeyComponents[index];
         PropagatorResult keyComponent2 = right.KeyComponents[index];
         if (keyComponent1.Identifier != -1)
         {
             if (keyComponent2.Identifier == -1 || this._manager.GetCliqueIdentifier(keyComponent1.Identifier) != this._manager.GetCliqueIdentifier(keyComponent2.Identifier))
             {
                 return(false);
             }
         }
         else if (keyComponent2.Identifier != -1 || !ByValueEqualityComparer.Default.Equals(keyComponent1.GetSimpleValue(), keyComponent2.GetSimpleValue()))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 6
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);
        }