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))
);
Source: stackoverflow.com
Related Query
- How to check search text contains in any field
- How to check if any word in my List<string> contains in text
- How to check list A contains any value from list B?
- How to use Linq to check if a list of strings contains any string in a list
- How to check if String contains any of the strings in List/Array
- Check if field contains any item from collection in LinqToSql
- How to search for empty strings in a text field with Entity Framework?
- How to use Linq where condition to check if a list of strings contains any string
- using linq to find if a text field contains any string in a list
- Check if text contains any string item from list of string c# linq
- How to search a text contains or not in particular column that contain Json object using linq
- Using LINQ how would I check if a XML row contains a field and if it does check a different field on the same row for a value
- How do I find the text within a div in the source of a web page using C#
- Entity Framework, Code First and Full Text Search
- LINQ: Entity string field contains any of an array of strings
- How to determine if a string contains any matches of a list of strings
- Check if a String value contains any number by using Lambda Expression
- Check if a string contains particular characters in any order
- Check if one list contains any elements from another
- How to search any property from a table with linq?
- How can I use linq to check if an flags/bitwise enumeration contains a type?
- How to check if XML contains element when using LINQ to XML?
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- How to check IEnumerable<DataRow> returns null or has any row?
- Check if values of Dictionary contains an element with certain field value
- How to use LINQ to find if any Value in a ResultPropertyCollection contains a certain substring?
- Linq, how to check if value of field is null
- how to search string in Linq to SQL using contains
- How to check if a char array contains every element in another char array?
- How to check CONTAINS with multiple values
More Query from same tag
- Linq : filter duplicated line without taking account a column
- Get Range of integers with linq
- Linq to Entities Group By (OUTER APPLY) "oracle 11.2.0.3.0 does not support apply"
- @foreach model is null :System.NullReferenceException: Object reference not set to an instance of an object
- mvc3 and linq - creating a ViewModel
- MongoDB LINQ ContainsAny Unsupported Filter
- What is the Linq Query expression to get all the department Id , Name in a select list variable for drop down
- More efficient ways for foreach loop to add database Items to results List?
- Name cannot begin with the '1' character, hexadecimal value 0x31. while reading from an xml file
- ASP.NET: Store user information on submit
- LINQ compare datetime.now ddmmyyyy
- In Linq, is Single() after a Where clause useful?
- Best mapping when domain model is exactly the same as view model?
- Make Reachable Class Out Of DataTable LINQToDataTable<T>()?
- Error in Linq Query when using anonymous return on List
- How to translate this inner join T-SQL into LINQ-to-Entities?
- Linq two tables in to one
- Returning the middle n (values not index) from a collection
- Pull objects out of List<T> by multiple Id's at once?
- To many nested statements
- entity framework linq query, get top N postIDs from favorite's table based on count
- Passing lambda expression to LINQ Include() (SharePoint CSOM)
- Linq query using ID returns result to slow (EF Core)
- OrderBy exception "At least one object must implement IComparable"
- Lazy loading or linq query?
- How to replace null by "NULL" in a List<string> without foreach loop?
- LINQ Convert string to datetime
- Why are anonymous types in .NET implemented as reference type?
- How to cope with Exceptions in Linq Queries?
- LINQ to SQL join with LINQ to DataSet