private bool IsPreferredParentForSelfJoin(IReference reference, IReference other) { if (reference.Other.HasFlag(ReferenceFlags.Many) && other.HasFlag(ReferenceFlags.Foreign)) { return(true); } else if (reference.Other.HasFlag(ReferenceFlags.One) && other.HasFlag(ReferenceFlags.Primary)) { return(true); } return(false); }
private void AssignEmptyChildKeys(ElementNode elementNode) { IList <MetadataNode> allNodes = elementNode.Value.Tree().ToList(); foreach (KeyNode parentKey in elementNode.ParentKeys) { IReference childReference = parentKey.Reference.Other; IBindingMetadata childMetadata; if (childReference.HasFlag(ReferenceFlags.Many)) { childMetadata = childReference.List.Identity.GetMetadata <IBindingMetadata>(); } else { childMetadata = childReference.Metadata.Identity.GetMetadata <IBindingMetadata>(); } MetadataNode thisNode = this.FindNode(allNodes, childMetadata); MetadataNode parentNode = this.FindNode(allNodes, childMetadata?.Parent); if (thisNode == null && parentNode != null && parentNode.Column == null) { MetadataNode joinNode = new MetadataNode(childMetadata) { ListIndex = parentKey.ParentIndex, ElementIndex = this.GetKeyIndex(parentKey.Reference.Other), }; parentNode.Properties.Add(joinNode); } } }
public int GetKeyIndex(IReference reference) { if (reference.HasFlag(ReferenceFlags.Child)) { int parentIndex = this.GetParentIndex(reference.Other.Metadata.Identity, reference.Other.Key); return(this.GetChildIndex(parentIndex, reference.Metadata.Identity, reference.Key)); } else { return(this.GetParentIndex(reference.Metadata.Identity, reference.Key)); } }
public static IReference Find(this IReference reference, ReferenceFlags flag) { if (reference.HasFlag(flag)) { return(reference); } else if (reference.Other.HasFlag(flag)) { return(reference.Other); } else { return(null); } }
private KeyNode CreateKey(IEnumerable <MetadataNode> nodes, IReference reference) { IList <MetadataNode> keyValue = reference.Key.Properties.Select(m => this.FindNode(nodes, m)).ToList(); if (keyValue.All(n => n?.Column != null)) { IReference parentReference = reference.HasFlag(ReferenceFlags.Parent) ? reference : reference.Other; KeyNode keyNode = new KeyNode(reference) { Value = keyValue, ParentIndex = this.GetKeyIndex(parentReference), }; if (reference.HasFlag(ReferenceFlags.Child)) { keyNode.ChildIndex = this.GetKeyIndex(parentReference.Other); } return(keyNode); } return(null); }
private bool IsValidJoinReference(IReference reference) { IReference childReference = reference.HasFlag(ReferenceFlags.Child) ? reference : reference.Other; return(childReference.HasFlag(ReferenceFlags.Many) || this.HasManyAttribute(childReference)); }