Reputation: 1379
How do we use a LIKE with wildcards in a custom sql with servicestack ORMLite?
Following code does not seem to work:
var sql="SELECT TOP 10 Id,Value FROM SomeTable WHERE Value Like '%@term%'"
var results = Db.Select<CustomDTO>(sql, new {term = "stringToSearch"})
Upvotes: 1
Views: 301
Reputation: 143359
You need to add the wildcard to the param value, e.g:
var sql = "SELECT Id,Value FROM SomeTable WHERE Value Like @term";
var results = db.Select<SomeTable>(sql, new { term = "%foo%" });
You can run this Live Example on Gistlyn to test it.
Upvotes: 2