5

After reading then question How to do SQL Like % in Linq? I still have doubts when I need to use wildcard inside the string, like this:

%cro%ft%

And get results like:

  • Microsoft
  • Microsoft Corporation
  • Acrobat software

For some reason, a simple contains does not works.

update:

Using .contains(string1) && .contains(string2), give me this sql command:

SELECT s."Nome", s."Id", s."Cpf"
  FROM "Pacientes" AS s
 WHERE ((STRPOS(s."Nome", 'cro') > 0) AND (STRPOS(s."Nome", 'ft') > 0))
   AND (s."ClinicaId" = @__clinicId_0)
 ORDER BY s."Nome"

instead of a clean sql like:

SELECT s."Nome", s."Id", s."Cpf"
  FROM "Pacientes" AS s
 WHERE (s.Nome like '%cro%ft%')
   AND (s."ClinicaId" = @__clinicId_0)
 ORDER BY s."Nome"

My code in production is:

result = result.Where(s => s.Nome.ToLower().Contains(name.ToLower()));
Beetlejuice
  • 4,292
  • 10
  • 58
  • 84

0 Answers0