using System.Collections.Generic;
public static void Main()
var peoplesAwaitingValidation =
new People{ id = 1 , externalId = "A" },
new People{ id = 2 , externalId = "B" },
new People{ id = 3 , externalId = "C" },
new People{ id = 4 , externalId = "D" },
new People{ id = 5 , externalId = "E" },
new People{ id = 6 , externalId = "F" },
var relationsAwaitingValidation =
new Relation{ id = 1 , sourceExternalId = "A", destExternalId = "B" },
new Relation{ id = 2 , sourceExternalId = "A", destExternalId = "C" },
new Relation{ id = 3 , sourceExternalId = "A", destExternalId = "D" },
new Relation{ id = 4 , sourceExternalId = "E", destExternalId = "A" },
new Relation{ id = 3 , sourceExternalId = "E", destExternalId = "B" }
var orderedPeoplesAwaitingValidation = new List<People> {
new People{ id = 5 , externalId = "E" },
new People{ id = 5 , externalId = "F" },
new People{ id = 1 , externalId = "A" },
new People{ id = 3 , externalId = "C" },
new People{ id = 4 , externalId = "D" },
new People{ id = 2 , externalId = "B" },
var step1 = peoplesAwaitingValidation
.GroupBy(g => g.externalId)
var step2 = relationsAwaitingValidation
.Select(x => x.sourceExternalId)
var step3 = relationsAwaitingValidation
.GroupBy(g => g.sourceExternalId)
group = g.Select(x => x.destExternalId).ToList()
for (int i = 0; i < step2.Count(); i++) {
for (int i = 0; i<step3.Count(); i++) {
foreach (var dest in item.group) {
step1[dest]=step1[dest]+2;
public string externalId;
public string postalInformation;
public string sourceExternalId;
public string destExternalId;