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)); }
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)); } }
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); } }
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); }
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;
public bool Equals(IReferenceKey other) => Equality.Combine(this, other, m => m.Name, m => m.Other);
public IndexKey(MetadataIdentity identity, IReferenceKey key) { this.Identity = identity ?? throw new ArgumentNullException(nameof(identity)); this.Key = key ?? throw new ArgumentNullException(nameof(key)); }