Pregunta

Estamos utilizando LINQ to EF para desarrollar una solución.

En mi consulta LINQ me gustaría

string toMatch = "Matt Cool";

newString = toMatch.Replace(" ", "% ") + "%"; 

// So here newString is 'Matt% Cool%'

/*Now in my datasource, there is no 'Matt Cool', there's 'Matthew Coolguy'.
I would like this query to return that result. 
I would expect this behavior with the 
wildcard. It doesn't work*/

var results = from a in mycontainer.users
              where a.fullname.equals(newString)
              select a.fullname;

Lo intenté " * " como un comodín y una solución de expresiones regulares, sin éxito - ¿Hay otras opciones?

¿Fue útil?

Solución

en lugar de usar Igual a intente usar Contiene esto debería tomar sus comodines porque LINQ usa internamente MEJOR cuando usa Contiene

var results = from a in mycontainer.users
              where a.fullname.Contains(newString)
              select a.fullname;

Otros consejos

Hay un gran artículo que describe cómo hacerlo: Regex en el marco de la entidad

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top