The LIKE
can be at the beginning, at the end or anywhere. So the equivalence is this:
From the documentation we see that the Contains()
is even less flexible. If you want to do box insensitivity, or comparison according to some specific criteria, you have to write an auxiliary code (text.IndexOf("Maria", StringComparison.OrdinalIgnoreCase) >= 0
).
using static System.Console;
using System.Collections.Generic;
using System.Linq;
public class Program {
public static void Main() {
var pessoas = new List<Pessoa>() {
new Pessoa() { Nome = "Maria José" },
new Pessoa() { Nome= "José Maria"},
new Pessoa() { Nome= "José Maria José"}
};
WriteLine("Início");
foreach (var pessoa in pessoas.Where(p => p.Nome.StartsWith("Maria")).OrderBy(p => p.Nome)) {
WriteLine(pessoa.Nome);
}
WriteLine();
WriteLine("Fim");
foreach (var pessoa in pessoas.Where(p => p.Nome.EndsWith("Maria")).OrderBy(p => p.Nome)) {
WriteLine(pessoa.Nome);
}
WriteLine();
WriteLine("Qualquer lugar");
foreach (var pessoa in pessoas.Where(p => p.Nome.Contains("Maria")).OrderBy(p => p.Nome)) {
WriteLine(pessoa.Nome);
}
}
}
public class Pessoa {
public string Nome;
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
See if this solution helps you: https://answall.com/a/482282/213393
– Tiago Santos