0

I am having list of object in which there are null values available in the list. If I want to filter based on few columns in that list using lambda. In this case I have to exclude the filter condition when there is a column comes with null value.

Ex: _db.test.select(x=>x.value1==a && value2==b).tolist();

In this example let's assume value1 has null value. At that time I don't want to use value1 for the condition. I have to eliminate value1 condition. I can go with rest of the conditions available in the lambda expression.

Jerom
  • 13
  • 1
  • 6

2 Answers2

1
enumerable.Where( x => ( x.value1 == null || x.value1 == a ) && x.value2 == b )

or

enumerable
.Where( x => x.value1 == null || x.value1 == a )
.Where( x => x.value2 == b )
ikegami
  • 367,544
  • 15
  • 269
  • 518
0

Inside Select() you can't set condition you must use Where(); Ex: _db.test.Where(x=>x.value1==a && value2==b).tolist();