Showing posts with label filter with multiple values. Show all posts
Showing posts with label filter with multiple values. Show all posts

Thursday 16 January 2020

filter collection from multiple values

Suppose we have a list MyList
Then we can take in enumerable like below

IEnumerable<TestObject> query = MyList;
if (obj1 != null) {
    query = query.Where(x => x.Id == obj1.ID);
}
if (obj2= null) {
    query = query.Where(x => x.Number.Contains(obj2.Number));
}
if (obje3 != null) {
    query = query.Where(x => x.Date == obj3.Date);
}
......
you can use many more
Finally we can convert in list, It basically reduce the complexcity

MYListView = query.ToList();