score:2
i think it's better to get the filtered collection, instead for perform search after getting the collection. so i suggest you to use a where clause like the following to get filtered items only:
string searchstring ="a";
from row in repos.gettable<table_names>()
where row.name.contains(searchstring)
select row.name;
instead for contains
you can also try startswith
if you want to get the collection of strings that starts with the given search text.
score:0
if you don't want to filter in the database, you can use linq to objects
to further filter the collection in memory:
var filtered = collectionname.where(item => item.contains("a")).toarray();
score:0
you can use sqlmethods.like in linq query. check the code below
private void combobox1_textchanged(object sender, eventargs e)
{
combobox1.datasource = getitems(combobox1.text);
combobox1.displaymember = "name";
combobox1.valuemember = "id";
}
public static list<comboboxitem> getitems(string text)
{
dataclasses1datacontext context = new dataclasses1datacontext();
try
{
list<comboboxitem> ilist = new list<comboboxitem>();
var query = from x in context.testcomboboxes where sqlmethods.like(x.name, '%' + text +'%') select x;
foreach (var q in query)
{
comboboxitem item = new comboboxitem();
item.id = q.id;
item.name = q.name;
ilist.add(item);
}
return ilist;
}
catch (exception ex)
{
return null;
}
}
public class comboboxitem
{
public object id { get; set; }
public string name { get; set; }
}
Source: stackoverflow.com
Related Query
- Linq into the array then find values in the array and list to combobox
- LINQ datarow string to array and then into to string list
- Find the Second Max in a list of values using linq c#
- Group by key and send values into list using LINQ
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- How to find how many times the same object appears in a list and then find a property of the most appeared object
- How can I concatenate all the column values in a row, and then concatenate all rows in a DataTable into a single string?
- Is a full list returned first and then filtered when using linq to sql to filter data from a database or just the filtered list?
- How to group by list of values and then count the amount of entries per value
- find list elements which are similar to other list elements by 3 properties and then add value from the second one to the first
- Convert List of array into the list of KeyValuePairs using LINQ
- Grouping values in a list and convert the output into JSON using C#
- LINQ - GroupBy a key of paired object, then separate the grouped object into list of 2 objects?
- C# LINQ Group and sum List<T> then Group and sum another list within the first List
- Compare values between 3 lists and add missing values from first list into the remaining 2 lists - C#
- Linq code to get the index of an object in an array from an object within a list
- Find a string in the list and change value of another property using linq (complicated)
- Search an Object list for duplicate keys, and place string values into a string array
- LINQ counting unique strings in a list and storing the values in a tuple
- Check for unique values in a list, and then increment the duplicates c# Linq
- LINQ Comparing two list and putting the results into one list
- How to iterate in a list to find names and values with linq
- How to sort by a specific key and then get the first result in the sorted collection into a group in LINQ
- C# Linq Comparing List Values using multiple fields and return item which doesn't satisfy the condition
- what is the LINQ statement to parse a byte array property of a list and copy the result in another list?
- C# LINQ statement with joins, group by and having then mapped into list object
- How to assign LINQ Query to a variable and then use it later in the code
- linq: how to divide a list into two by the sum of the values and keeping the input order
- Dicionary intersect keys with list and get in result dicionary with values at the beggining LINQ
- LINQ Query with multiple conditions and setting values into a list
More Query from same tag
- Select at runtime the field in a table with LINQ to SQL
- SQL Query to Lambda C#
- Linq Query Message: Specified cast is not valid
- ADO.NET Entity Model Update
- Invalid parameter size value -1
- how to return the query result as a specific object type in LINQ
- Implementing DateTime.ToString(string) with Linq to Entities
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- Taking 2 attributes from XElement to create a dictionary LINQ
- VB.NET Datatable.Select expression
- How to choose columns from a query and display in datagrid
- how to subtract two datatables with linq
- problem with a join
- Does ToLookup forces immediate execution of a sequence
- Get excel cell value with Row and Column Position through open xml sdk linq query
- How to find specific number from array?
- I cant get the values from xml document
- LINQ: Field could be int or bool - how can I use it without InvalidCastException?
- Linq: select from multiple tables into one pre-defined entity
- How to convert nested object from one type to another
- Multiple sums in a single LINQ query fire multiple SQL queries
- List<T> All rows update
- How can I get the first value of an IEnumerable iff the length is exactly one, or default otherwise?
- LINQ to add continuous records based on a flag to JSON
- Selecting elements from array according to indices specified in another array c#
- Exception handling in Linq queries
- LINQ order outer list by property of inner list
- Search, Add and update using LINQ
- How can I use LINQ, to Sort and Filter items in a List<ReturnItem> collection?
- How to Sortby Multiple Colums - Linq to SQL