web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Remove Dataverse Relat...
Power Apps
Answered

Remove Dataverse Relationship in C# Plugin

(0) ShareShare
ReportReport
Posted on by 559

Hello Community!

 

I have the following usecase: A Trainee get's deleted from a Training. That training has Extra Costs which are related to the Trainee. On deleting the Trainee from the Training the Trainee should get unrelated from his Extra Costs (which doesn't happen now). Is it possible in C# syntax to unrelate Extra Cost ID from TraineeID?

 

This is how the relations are build:

  • Training 1:M Extra Costs
  • Trainee M:M Extra Costs

Best Regards,

Anthony

I have the same question (0)
  • Verified answer
    AnthonyD Profile Picture
    559 on at

    Somehow it was easier then i expected. Here is where i found the solution:

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/org-service/entity-operations-associate-disassociate

     

    And this is the code i used (it compares 2 collections and adds the matching  ounces to a collection. These are the ounces to unrelate)

    double traineeExtraKostKost=0;
     EntityCollection TraineeExtraKostsCollection = new EntityCollection();
     foreach (var extrakost in opleidingExtraKostResult.Entities)
     {
     foreach (var traineeExtraKost in cursistExtraKosts.Entities)
     {
     if (traineeExtraKost.Id==extrakost.Id)
     {
     traineeExtraKostKost += Convert.ToDouble(traineeExtraKost.Attributes.FirstOrDefault(q => q.Key == "cref8_prijs").Value);
     TraineeExtraKostsCollection.Entities.Add(extrakost);
     }
     }
     
     }
     var extraKostReference = new EntityReferenceCollection();
     TraineeExtraKostsCollection.Entities.ToList().ForEach(x =>
     {
     extraKostReference.Add(x.ToEntityReference());
     });
     var relationship = new Relationship("cref8_ExtraKost_cref8_Cursist_cref8_Cursi");
     service.Disassociate("cref8_cursist", relatedEntity.Id, relationship, extraKostReference);

     

    Best Regards,

    Anthony

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard