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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard