Wildcard search for LINQ
I would use Regular Expressions, since you might not always be using Linq to SQL.
Like this example of Linq to Objects
List<string> list = new List<string>();
list.Add("This is a sentence.");
list.Add("This is another one.");
list.Add("C# is fun.");
list.Add("Linq is also fun.");
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex("This");
var qry = list
.Where<string>(item => regEx.IsMatch(item))
.ToList<string>();
// Print results
foreach (var item in qry)
{
Console.WriteLine(item);
}
add System.Data.Linq.SqlClient to your using or imports list then try:
var results= from x in data
where SqlMethods.Like(x.SearchField, “%something%like%this%”)
select x;
You can use SqlMethods.Like().
An example of the usage:
var results =
from u in users
where SqlMethods.Like(u.FirstName, "%John%")
select u;