I have a Windows application written in C # that should load 250,000 rows from the database and provide a โsearch as you typeโ function, which means that as soon as the user types something in the text box, the application should search for everything 250,000 records (this is a bit, one column with 1000 characters in each row) using like search and display found records.
The approach I used was as follows:
1- The application loads all entries in the printed List<EmployeeData>
while (objSQLReader.Read()) { lstEmployees.Add(new EmployeesData( Convert.ToInt32(objSQLReader.GetString(0)), objSQLReader.GetString(1), objSQLReader.GetString(2))); }
2- In the TextChanged event, using LINQ , I do a search (with a combination of regular expressions) and attach an IEnumerable<EmployeesData> to the ListView, which is in virtual mode.
String strPattern = "(?=.*wood*)(?=.*james*)"; IEnumerable<EmployeesData> lstFoundItems = from objEmployee in lstEmployees where Regex.IsMatch(Employee.SearchStr, strPattern, RegexOptions.IgnoreCase) select objEmployee; lstFoundEmployees = lstFoundItems;
3 RetrieveVirtualItem is processed to display items in a ListView to display an item.
e.Item = new ListViewItem(new String[] { lstFoundEmployees.ElementAt(e.ItemIndex).DateProjectTaskClient, e.ItemIndex.ToString() });
Although lstEmployees loads relatively quickly (1.5 seconds) to load a list from SQL Server, a search in TextChanged requires a search in more than 7 minutes using LINQ. Searching through SQL Server directly by doing a like search takes less than 7 seconds.
What am I doing wrong here? How to speed up this search (no more than 2 seconds)? This is a requirement from my client. Therefore, any help is much appreciated. Please, help...