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:
Best Regards,
Anthony
Somehow it was easier then i expected. Here is where i found the solution:
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
WarrenBelz
109
Most Valuable Professional
Michael E. Gernaey
76
Super User 2025 Season 1
mmbr1606
71
Super User 2025 Season 1