In the UI, there’s a dropdown that takes value for parameter ‘field’. It can be a specific value or ‘All’ is the default where all rows irrespective of ‘field’ value needs to be retrieved.
How do I write the Where clause in LINQ such that if user supplies a value for field column, then use it as filter otherwise grab all rows from DB?
You can use
IQueryable<T>as a base for your LINQ query and append to it all you need:Example: