Kevin H
Kevin H

Reputation: 25

EF Linq search results while ignoring special characters

I'm trying to create a LINQ method query where a user can input text for search criteria which will search a table column and ignore special characters when looking for the results.

For example: Inputting "ab cd" would result in returning both "ab cd" and "ab, cd".

My LINQ Method is currently the following:

public List<type> GetData(string input)
{ 
    var results = dbContext.table
                  .Where(s => s.Column.Contains(input))
                  .ToList();
    return results;
}

Upvotes: 1

Views: 2066

Answers (1)

NetMage
NetMage

Reputation: 26917

You can use DbFunctions.Like as of EF 6.2:

public List<type> GetData(string input)
{ 
    var results = dbContext.table
                  .Where(s => DbFunctions.Like(s.Column, "%"+input.Replace(' ', '%')+"%"))
                  .ToList();
    return results;
}

Upvotes: 2

Related Questions