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
- Adding unique data with Entity Framework
- Average of null list throws Exception on Razor View
- MongoDB: retrieve, filter and sort MongoDB embedded collections
- Multiple enumeration of IEnumerable
- Linq to Entity Join and Group By
- How do I use a lambda expression in C# to process a matrix LinkedList<Object>?
- Linq - between dates query
- XElement and XName crashes when xml has namespace to root node
- New transaction is not allowed because there are other threads running in the session. Entity Framework
- Iterate through LINQ AnonymousType object
- IEnumerable.Select() when attribute is known only at runtime
- how to write a Precompiled query?
- How does this LINQ Expression work?
- linq default value if no records
- Edit: Merge list into another list that is null, it is possible?
- In asp.net mvc what is the difference in using "new" and not using "new" in select query
- Is there a way to Sum SQLFunction.DateDiff inside a LINQ query?
- Inserting records on multiple tables in a single method using Entity Framework
- Validate Value Exists in multiple columns of DataTable
- How to group by multiple columns with joins using linq
- How to insert the LINQ result to a string[] array
- Left Join in Linq and using the variable for other joins
- Getting a list of users with their assigned role in Identity 2
- Using LINQ to filter on a variable number of parameters in c#
- Multiple Sum using Linq (lambda expression)
- read text file and writing to a list
- Nhibernate and Query example
- Replace sequence of duplicates
- Group dateTime by hour range
- Generating a query with related data and conditions using LINQ expressions