To convert the SQL LIKE query to LINQ which having "%"(percentage) operators both at the start and end of the string, we use the Contains()
method.
e.g.
SELECT * FROM [User] WHERE Username LIKE '%test%'
The equivalent LINQ is:
var users = (from usr in Context.Users
where usr.Username.Contains("test")
select usr).ToList();
What will be equivalent of the below query which contains multiple "%"(percentage) operators in the input text?
SELECT * FROM [User] WHERE Username LIKE '%test%email%'
Any help is appreciated.
Note: The query will be executed in the EntityFramework(version 6.1.3)
Posting the comments given by @Fabio and @CodeNotFound as answer for reference.
In EntityFramework version 6.2.0:
var users = (from usr in Context.Users
where DbFunctions.Like(usr.Username, "%test%email%")
select usr).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With