public void SetCommunityNodes() { if (Communities.Count == 0) { throw new Exception("There are no communities"); } foreach (Community <T> community in Communities) { community.CommunityNodes = new HashSet <Node <T> >(); } foreach (Node <T> node in Nodes) { Communities.First(x => x.Id == node.CommunityId).CommunityNodes.Add(node); } }