private static QueryItem PropToTable(PropertyReference prop) { var join = prop.Table.Joins .Select(j => AmlJoin.TryCreate(prop.Table, j, out var amlJoin) ? amlJoin : null) .FirstOrDefault(j => j?.IsRelationship() == true && string.Equals(j.Table.Type, prop.Name, StringComparison.OrdinalIgnoreCase)); if (join != null) { return(join.Table); } var right = new QueryItem(prop.Table.Context) { Type = prop.Name }; prop.Table.Joins.Add(new Join() { Condition = new EqualsOperator() { Left = new PropertyReference("id", prop.Table), Right = new PropertyReference("source_id", right) }, Type = JoinType.LeftOuter, Left = prop.Table, Right = right }); return(right); }
public static bool TryCreate(QueryItem parent, Join join, out AmlJoin amlJoin) { amlJoin = new AmlJoin(); if (!(join.Condition is EqualsOperator eq)) { return(false); } var props = new[] { eq.Left, eq.Right } .OfType <PropertyReference>() .ToArray(); if (props.Length != 2) { return(false); } amlJoin.CurrentProp = props.Single(p => ReferenceEquals(p.Table, parent)); amlJoin.OtherProp = props.Single(p => !ReferenceEquals(p.Table, parent)); amlJoin.Table = amlJoin.OtherProp.Table; return(true); }