Quote:
I would like to extract the list of Side where the position which is above 0 and below 6 but when I do the request :
List<side> listNozzleBySide = SectionList.SelectMany(x => x.SideList.Where(y => y.PositionList.Any(z => z.Position >= 1 && z.Position <=5))).ToList();
the position 0 and 6 rest present in the list of side.
Well... i'll try to explain it. Imagine, you've got 120 students in 4 classes (30 students in a class). You want to get students with red socks on their legs. Assuming that in each class there's at least one student with red socks, each class is meeting your criteria. Got it?
If NO, you have to get students instead of classes.
As to your example, you have to get positions insteads of sides.
Take a look at example:
void Main()
{
School school = new School(){Classes = new List<SchoolClass>()
{
new SchoolClass(){ClassID = 1, ClassName="A", Students = new List<Student>()
{
new Student(){StuID = 1, Name="Maciej", ColorOfSocks="yellow"},
new Student(){StuID = 5, Name="Anna", ColorOfSocks="red"},
new Student(){StuID = 22, Name="Robert", ColorOfSocks="green"}
}},
new SchoolClass(){ClassID = 2, ClassName="B", Students = new List<Student>()
{
new Student(){StuID = 2, Name="Fred", ColorOfSocks="black"},
new Student(){StuID = 3, Name="Viana", ColorOfSocks="gray"},
new Student(){StuID = 21, Name="Julia", ColorOfSocks="red"}
}}
}};
var cla = school.Classes.Where(c=>c.Students.Any(s=>s.ColorOfSocks=="red"));
var stu = school.Classes.Select(c=>c.Students.Where(s=>s.ColorOfSocks=="red"));
}
public class School
{
public List<SchoolClass> Classes = new List<SchoolClass>();
}
public class SchoolClass
{
public int ClassID {get; set;}
public string ClassName {get; set;}
public List<Student> Students = new List<Student>();
}
public class Student
{
public int StuID {get; set;}
public string Name {get; set;}
public string ColorOfSocks {get; set;}
}