I am writing an sql query for search where the users searches according to the FirstName and LastName. The query works fine when searched for FirstName or LastName, but when I search for FirstName and LastName(ie space between FirstName and LastName), it gives out blank result. The query string looks like this:
http://localhost:4562/api/User/Search?q=sumedha%20v&filters=&offset=3&limit=9
The sql query is : List<AppUser> searchedAppUsers = await _context.AppUser.Where(u => u.Profile.FirstName.StartsWith(q) || u.Profile.LastName.StartsWith(q)).ToListAsync();
I tried using Contains()
instead of StartsWith()
but it still gives a blank result. I also tried using SqlMethods.Like()
but couldn't see it in the intellisense. I tried using SqlFunctions.PatIndex()
, but same problem. I tried to follow this post, but dint get how to do it.
Is there any other way? or am I going wrong somewhere?