Пример #1
0
        private bool IsKeyMatch(IReferenceKey rightKey, IReferenceKey leftKey)
        {
            if (leftKey.Properties.Count != rightKey.Properties.Count)
            {
                return(false);
            }

            bool leftIsCandidate  = leftKey.HasFlag(ReferenceKeyFlags.Candidate);
            bool rightIsCandidate = rightKey.HasFlag(ReferenceKeyFlags.Candidate);

            bool leftIsForeign  = leftKey.HasFlag(ReferenceKeyFlags.Foreign);
            bool rightIsForeign = rightKey.HasFlag(ReferenceKeyFlags.Foreign);

            IReferenceKey candidateKey, foreignKey;

            if (leftIsCandidate && rightIsForeign)
            {
                candidateKey = leftKey;
                foreignKey   = rightKey;
            }
            else if (leftIsForeign && rightIsCandidate)
            {
                candidateKey = rightKey;
                foreignKey   = leftKey;
            }
            else
            {
                return(false);
            }

            return(foreignKey.Other.Equals(candidateKey.Name, StringComparison.Ordinal));
        }
        private bool IsKeyMatch(IReferenceKey rightKey, IReferenceKey leftKey)
        {
            if (leftKey.Type == rightKey.Type || leftKey.Properties.Count != rightKey.Properties.Count)
            {
                return(false);
            }

            IReferenceKey candidateKey = rightKey.Type == ReferenceKeyType.CandidateKey ? rightKey : leftKey;
            IReferenceKey foreignKey   = rightKey.Type == ReferenceKeyType.ForeignKey ? rightKey : leftKey;

            return(foreignKey.Other.Equals(candidateKey.Name, StringComparison.Ordinal));
        }
Пример #3
0
        private int GetParentIndex(MetadataIdentity identity, IReferenceKey key)
        {
            IndexKey parentKey = new IndexKey(identity, key);

            if (this.parentMap.TryGetValue(parentKey, out int parentIndex))
            {
                return(parentIndex);
            }

            lock (this.state)
            {
                return(this.parentMap.GetOrAdd(parentKey, this.parentMap.Count));
            }
        }
Пример #4
0
        private int GetChildIndex(int parentIndex, MetadataIdentity identity, IReferenceKey key)
        {
            IndexKey childKey = new IndexKey(identity, key);

            if (this.childMap.TryGetValue(childKey, out int childIndex))
            {
                return(childIndex);
            }

            lock (this.state)
            {
                if (!this.childMap.TryGetValue(childKey, out childIndex))
                {
                    childIndex = this.childSizes.TryGetValue(parentIndex);

                    this.childSizes[parentIndex] = childIndex + 1;
                    this.childMap.TryAdd(childKey, childIndex);
                }

                return(childIndex);
            }
        }
Пример #5
0
        private bool IsValidJoinKey(KeyReader joinKey, bool throwOnInvalid = false)
        {
            IReferenceKey parentKey = joinKey.Reference.FindParentKey();
            IReferenceKey childKey  = joinKey.Reference.FindChildKey();

            foreach (var(childValue, parentValue) in childKey.Properties.Zip(parentKey.Properties))
            {
                Type parentType = parentValue.Type.GetKeyType();
                Type childType  = childValue.Type.GetKeyType();

                if (parentType != childType && throwOnInvalid)
                {
                    throw BindingException.InvalidReference(joinKey.Reference);
                }
                else if (parentType != childType)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #6
0
        private IEnumerable <Type> GetKeyType(IReference reference)
        {
            IReferenceKey candidateKey = reference.Key.Type == ReferenceKeyType.CandidateKey ? reference.Key : reference.Other.Key;

            return(candidateKey.Properties.Select(m => Nullable.GetUnderlyingType(m.Type) ?? m.Type));
        }
 public static bool HasAnyFlag(this IReferenceKey key, ReferenceKeyFlags flag) => (key.Flags & flag) != ReferenceKeyFlags.None;
 public static bool HasFlag(this IReferenceKey key, ReferenceKeyFlags flag) => (key.Flags & flag) == flag;
Пример #9
0
 public bool Equals(IReferenceKey other) => Equality.Combine(this, other, m => m.Name, m => m.Other);
Пример #10
0
 public IndexKey(MetadataIdentity identity, IReferenceKey key)
 {
     this.Identity = identity ?? throw new ArgumentNullException(nameof(identity));
     this.Key      = key ?? throw new ArgumentNullException(nameof(key));
 }