Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

Linq to Entities: usare LIKE con wildcard nel mezzo

In Entity Framework puoi usare SqlFunctions.PatIndex, che segue le regole dell’operatore LIKE:

dt.Table.Where(p => SqlFunctions.PatIndex(term, p.fieldname) > 0);

Supporta i caratteri jolly principali:

  • %: zero o più caratteri.
  • _: un singolo carattere.
  • [ ]: un carattere in un intervallo o set.
  • [^]: un carattere non nell’intervallo o set.

Spesso è disponibile anche quando SqlMethods.Like non lo è.