2017-02-13 105 views
1

我們如何在自定義SQL中使用帶有通配符的LIKE與服務堆ORMLite?ServiceStack ORM Lite自定義SQL LIKE語句通配符

下面的代碼似乎沒有工作:

var sql="SELECT TOP 10 Id,Value FROM SomeTable WHERE Value Like '%@term%'" 
var results = Db.Select<CustomDTO>(sql, new {term = "stringToSearch"}) 

回答

1

你需要將通配符添加到參數值的方式,e.g:

var sql = "SELECT Id,Value FROM SomeTable WHERE Value Like @term"; 
var results = db.Select<SomeTable>(sql, new { term = "%foo%" }); 

可以run this Live Example on Gistlyn to test it