score:2

Accepted answer

If you need to search on four fields, you can continue to expand your OR conditions to include the additional fields.

var result = LogData.Where(x => (
    searchText == "" || 
    x.Location.Contains(searchText) || 
    x.Messsage.Contains(searchText) || 
    x.Sender.Contains(searchText) ||
    x.AccountName.Contains(searchText))
); 

As Charlieface mentioned, you can potentially optimize this a bit by treating searchText == "" as an early exit condition and return your collection without a where clause.

var result = searchText == "" ? LogData : LogData.Where(x => (
    x.Location.Contains(searchText) || 
    x.Messsage.Contains(searchText) || 
    x.Sender.Contains(searchText) ||
    x.AccountName.Contains(searchText))
); 

Related Articles