如何在OrmLite中对INT列进行LIKE比较?

时间:2015-01-29 23:56:10

标签: sql-server int servicestack ormlite-servicestack sql-like

我想使用ServiceStack.OrmLite在LIKE列上进行sql INT比较。基本上我需要OrmLite来生成以下sql where子句:

where intColumn like '%123%'

我知道我可以在.Contains()上使用strings,但我的属性/列是int。 在.ToString().Contains()属性上使用int也会引发以下异常:

System.NotSupportedException: Specified method is not supported.
at ServiceStack.OrmLite.SqlExpression`1.VisitColumnAccessMethod(MethodCallExpression m)
   at ServiceStack.OrmLite.SqlExpression`1.VisitMethodCall(MethodCallExpression m)
   at ServiceStack.OrmLite.SqlExpression`1.Visit(Expression exp)
   at ServiceStack.OrmLite.SqlExpression`1.VisitColumnAccessMethod(MethodCallExpression m)
   at ServiceStack.OrmLite.SqlExpression`1.VisitMethodCall(MethodCallExpression m)
   at ServiceStack.OrmLite.SqlExpression`1.Visit(Expression exp)
   at ServiceStack.OrmLite.SqlExpression`1.VisitLambda(LambdaExpression lambda)
   at ServiceStack.OrmLite.SqlExpression`1.Visit(Expression exp)
   at ServiceStack.OrmLite.SqlExpression`1.AppendToWhere(String condition, Expression predicate)
   at ServiceStack.OrmLite.SqlExpression`1.Where(Expression`1 predicate)

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您应该只能附加自定义SQL Where条件:

 var results = db.From<Table>(q => q.Where("intColumn like '%123%'"));