scoob
scoob

Reputation: 1379

ServiceStack ORM Lite custom sql LIKE statement wildcard

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

Answers (1)

mythz
mythz

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

Related Questions