Wildcard search for LINQ

PlayKid picture PlayKid · Jun 24, 2009 · Viewed 60k times · Source

I would like to know if it is possible to do a wildcard search using LINQ.

I see LINQ has Contains, StartsWith, EndsWith, etc.

What if I want something like %Test if%it work%, how do I do it?

Regards

Answer

Ryan Versaw picture Ryan Versaw · Jun 24, 2009

You can use SqlMethods.Like().

An example of the usage:

var results =
        from u in users
        where SqlMethods.Like(u.FirstName, "%John%")
        select u;