Search code examples
c#.netdynamics-crmxrm

Replace associated entities


I'm using Microsoft.Xrm.Sdk for Dynamics 365.

Let's say I have an entity Movie and Tag. A Movie has multiple Tags.

Let's associate the tags A & B to the movie X.

EntityReferenceCollection tags = new EntityReferenceCollection();
tags.Add(new EntityReference("tag", "A"));
tags.Add(new EntityReference("tag", "B"));
svc.Associate("movie", "X", new Relationship("movie_tag"), tags);

Now imagine I need to link new tags

How can I replace these tags with new ones ?

Do I have to retreive the already associated tags, disassociate them one by one, and associate the new ones ?


Solution

  • Yes, you need "retreive the already associated tags, disassociate them one by one, and associate the new ones".

    Note you disassociate also takes a collection so you remove multiple in a single call.