Skip to content

Import N:N relationships from a table to itself - #28

Merged
imranakram merged 1 commit into
masterfrom
fix/self-referencing-intersect
Oct 9, 2026
Merged

imranakram merged 1 commit into
masterfrom
fix/self-referencing-intersect

Conversation

@imranakram

Copy link
Copy Markdown
Collaborator

An intersect block for an N:N relationship from a table to itself failed on import for every record.

The cause

In a self-referencing N:N relationship the intersect columns are named <table>idone and <table>idtwo. The intersect import worked out each side's table by removing a trailing id from the column name, so it asked Dataverse for a table called <table>idone:

The entity with a name = 'new_categoryidone' with namemapping = 'Logical' was not found in the MetadataCache

The fix

A small TableOfIntersectColumn helper in ShuffleDataImport removes idone, idtwo or id. The rest of the intersect import is unchanged.

The other half of the issue - Dataverse needs PrimaryEntityRole on an associate for a reflexive relationship - was already handled: Associate in Xrm.Utils.Core sets EntityRole.Referencing when both sides are the same table. It just never got that far, because the table names were wrong.

Tests

New IntersectImportTests:

  • A relationship from a table to itself associates both records as that table, with PrimaryEntityRole = Referencing. This test fails without the fix: the request went out as new_categoryidone.
  • A relationship between two different tables (accountid / contactid) still resolves to account and contact, without a role.

All 274 tests pass in Debug and Release. The README and the Runner and Deployer release notes have a line for it.

Fixes #27

In a self-referencing N:N relationship the intersect columns are named
<table>idone and <table>idtwo. The intersect import worked out each side's
table by removing a trailing "id", so it asked for a table called
<table>idone and every record failed. TableOfIntersectColumn now removes
idone and idtwo as well. Xrm.Utils.Core's Associate already sets
PrimaryEntityRole when both sides are the same table, so with the right
names the association goes through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@imranakram
imranakram merged commit 74e464c into master Oct 9, 2026
2 checks passed
@imranakram
imranakram deleted the fix/self-referencing-intersect branch October 9, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing an N:N relationship from a table to itself fails for every record

1 participant