0

We have a list of object which contains a list of object how to can filter out the on some conditions.

public class Person
{
    public int Id { get;; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }      
    public bool IsStudent { get; set; }
    public string Studentcode { get; set; }
    public List<Hobbies> Hobbies { get; set; }
    public bool Deleted { get; set; }
} 
public class Hobbies
{
    public int Id { get;; set; }
    public string Name{ get; set; }
    public int Kind { get; set; }
}


 bool isStudent = true;//comes from funtion call 
 Expression<Func<Person, bool>> PersonFilter = x => !x.Deleted;
 Expression<Func<Hobbies, bool>> HobbiesFilter = y => y.Kind>1 && y.Kind<100;

 if(isStudent )
 {
   Expression<Func<Person, bool>> codeFilter = x => x.Studentcode.Contains("CSE");
 }

How can I merge both PersonFilter and codeFilter So I can get the list of person with the filter

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

0 Answers0