Skip to content

Commit

Permalink
Showing M:1 and 1:M on link-entity - very clearer now! #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Apr 24, 2024
1 parent 7b037c7 commit b1e1717
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions FetchXmlBuilder/Builder/TreeNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public static void SetNodeText(TreeNode node, FetchXmlBuilder fxb, bool validate
}
if (node.Value("link-type") is string linktype && !string.IsNullOrEmpty(linktype))
{
text += $" ({linktype})";
text += $" {linktype}";
}
if (node.Value("intersect") == "true")
if (GetLinkDirection(node, fxb) is string direction && !string.IsNullOrEmpty(direction))
{
text += " M:M";
text += $" {direction}";
}
break;

Expand Down Expand Up @@ -316,6 +316,42 @@ public static void SetNodeText(TreeNode node, FetchXmlBuilder fxb, bool validate
}
}

private static string GetLinkDirection(TreeNode node, FetchXmlBuilder fxb)
{
if (fxb.entities == null)
{
return string.Empty;
}
var linkentity = node.Value("name");
var parentname = node.Parent.Value("name");
var from = node.Value("from");
var to = node.Value("to");
var parent = fxb.entities.FirstOrDefault(e => e.LogicalName == parentname);
if (parent == null)
{
return string.Empty;
}
if (parent.OneToManyRelationships.Any(r =>
r.ReferencingEntity == linkentity &&
r.ReferencingAttribute == from &&
r.ReferencedAttribute == to))
{
return "1:M";
}
if (parent.ManyToOneRelationships.Any(r =>
r.ReferencedEntity == linkentity &&
r.ReferencingAttribute == to &&
r.ReferencedAttribute == from))
{
return "M:1";
}
if (node.Value("intersect") == "true")
{
return "M:M";
}
return string.Empty;
}

public static void Validate(TreeNode node, FetchXmlBuilder fxb)
{
var root = node;
Expand Down

0 comments on commit b1e1717

Please sign in to comment.