question

JROW-1086 avatar image
0 Votes"
JROW-1086 asked AgaveJoe edited

Multi string search

Hey All,

I have a datatable, of which I am doing all of the functionality on the server side. However, I am a little stuck as to how to search for two strings from separate columns.

For example John Smith should bring up all john smiths in the table, below is a snippet of my search function


   archiveData = archiveData.Where(m => m.Forename.Contains(searchValue.ToLower())
                                                 || m.Surname.Contains(searchValue.ToLower())
                                                 || m.Patient_Id.Contains(searchValue)
                                                 || m.Request_Date.ToString().Contains(searchValue));


I understand that I need to split the string at the space at the end of the forename column then join on to the surname somehow but im a little stuck. Im still getting to grips with c#

dotnet-aspnet-core-razor
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Usually an application is designed to filters for each database column. It's very unusual and not recommended to submit a single string that contains 4 different possible column values. I recommend fixing the design.

Secondly, LINQ allows you to add filters to a query. The programming pattern is shown below. The code is not test.


 var query = db.archiveData.Where(m => m.Forename.Contains(forename.ToLower()));
 if(!string.IsNullOrEmpty(surname)) 
 {
     query.Where(m => m.Surname.Contains(surname.ToLower());
 }
    
 var results = query.ToList();

1 Vote 1 ·

0 Answers