I have 3 classes:
public class Disciplina
{
public int Key { get; set; }
public string Name { get; set; }
public string[] Semestr { get; set; }
public int Time { get; set; }
public List<int> TimeToAll { get; set; }
public string Otchetnost { get; set; }
public int Specialnost { get; set; }
...
}
public class Cafedra
{
public int Key { get; set; }
public string Name { get; set; }
public string Facultet { get; set; }
public string Telefone { get; set; }
public List<int> Specializations { get; set; }
...
}
public class Specialization
{
public int Key { get; set; }
public string Name { get; set; }
public string SpecialName { get; set; }
public string FormaObuch { get; set; }
public string[] DisplinsID { get; set; }
...
}
I need to choose all Disciplina of chosen cafedra. I created by many foreach but I need it with linq.
I tried, but one Cafedra can have a lot of Specialization, and the Specialization can have a lot of Disiplins and I do not know how it can be chosen in a LINQ?
My method
private static void DiscipliniCafedri()
{
Console.WriteLine("Выберите кафедру:");
for (int i = 0; i < Cafedras.Count; i++)
{
Console.WriteLine(i + 1 + " " + Cafedras[i].ToString());
}
int ID = Convert.ToInt32(Console.ReadLine());
List<Specialization> spesc = new List<Specialization>();
Console.Clear();
Console.WriteLine("Дисциплины выбранной кафедры:");
foreach (int s in Cafedras[ID - 1].Specializations)
{
spesc.Add(Specializations[s - 1]);
}
foreach (Specialization s in spesc)
{
foreach (string d in s.DisplinsID)
{
Console.WriteLine(Disciplinas[Convert.ToInt32(d) - 1].Name);
}
}
}