Complex string matching with LINQ to Entity Framework
We are using LINQ to EF to develop a solution.
In my LINQ query I would like
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;
I tried "*" as a wildcard and a regex solution, to no avail -- Are there any other options开发者_StackOverflow社区?
instead of using Equals try using Contains this should take your wild cards because internally LINQ uses LIKE when you use Contains
var results = from a in mycontainer.users
where a.fullname.Contains(newString)
select a.fullname;
There's a great article that describes how to do it: Regex in entity framework
精彩评论