0

I am trying to implement broad searching functionality from my database. Let's say I have an entity that has multiple attributes such as: Student has firstName, lastName, address, etc...

What is the best way to search my database to find any record that has matching attributes?

var Result = _context.Student.Where(s => 
    s.firstName.Contains(query) 
    || s.lastName.Contains(query) 
    || s.address.Contains(query)))
    .ToList();

Is there a better and faster way to do the search?

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
aqteifan
  • 456
  • 1
  • 5
  • 17
  • Honestly, I'd probably start where you did and go with it until the performance became a problem. I can think of a few marginally faster ways, but they all increase overhead in other areas. – Louis Ingenthron Jan 16 '19 at 21:18
  • I suggest if you have more request for this database query, then try indexing the columns for faster search. – Farshan Jan 16 '19 at 21:23
  • i dont think that there is any, but if you have really big amount of data then you should try indexing the search result like google dose in a diffrent table. and also dont forget to use pagination, Take and Skip – Alen.Toma Jan 16 '19 at 21:40

1 Answers1

1

When you have lots of data, consider indexing. Please check out those links:

How does database indexing work

Search engine indexing

SomoKRoceS
  • 2,934
  • 2
  • 19
  • 30