@@ -2155,81 +2155,60 @@ protected virtual object VisitColumnAccessMethod(MethodCallExpression m)
2155
2155
statement = string . Format ( "lower({0})" , quotedColName ) ;
2156
2156
break ;
2157
2157
case "StartsWith" :
2158
- if ( ! OrmLiteConfig . StripUpperInLike )
2159
- {
2160
- statement = string . Format ( "upper({0}) like {1}{2}" ,
2158
+ statement = ! OrmLiteConfig . StripUpperInLike
2159
+ ? string . Format ( "upper({0}) like {1}{2}" ,
2161
2160
quotedColName ,
2162
2161
ConvertToParam ( wildcardArg . ToUpper ( ) + "%" ) ,
2163
- escapeSuffix ) ;
2164
- }
2165
- else
2166
- {
2167
- statement = string . Format ( "{0} like {1}{2}" ,
2162
+ escapeSuffix )
2163
+ : string . Format ( "{0} like {1}{2}" ,
2168
2164
quotedColName ,
2169
2165
ConvertToParam ( wildcardArg + "%" ) ,
2170
2166
escapeSuffix ) ;
2171
- }
2172
2167
break ;
2173
2168
case "EndsWith" :
2174
- if ( ! OrmLiteConfig . StripUpperInLike )
2175
- {
2176
- statement = string . Format ( "upper({0}) like {1}{2}" ,
2169
+ statement = ! OrmLiteConfig . StripUpperInLike
2170
+ ? string . Format ( "upper({0}) like {1}{2}" ,
2177
2171
quotedColName ,
2178
2172
ConvertToParam ( "%" + wildcardArg . ToUpper ( ) ) ,
2179
- escapeSuffix ) ;
2180
- }
2181
- else
2182
- {
2183
- statement = string . Format ( "{0} like {1}{2}" ,
2173
+ escapeSuffix )
2174
+ : string . Format ( "{0} like {1}{2}" ,
2184
2175
quotedColName ,
2185
2176
ConvertToParam ( "%" + wildcardArg ) ,
2186
2177
escapeSuffix ) ;
2187
- }
2188
2178
break ;
2189
2179
case "Contains" :
2190
- if ( ! OrmLiteConfig . StripUpperInLike )
2191
- {
2192
- statement = string . Format ( "upper({0}) like {1}{2}" ,
2180
+ statement = ! OrmLiteConfig . StripUpperInLike
2181
+ ? string . Format ( "upper({0}) like {1}{2}" ,
2193
2182
quotedColName ,
2194
2183
ConvertToParam ( "%" + wildcardArg . ToUpper ( ) + "%" ) ,
2195
- escapeSuffix ) ;
2196
- }
2197
- else
2198
- {
2199
- statement = string . Format ( "{0} like {1}{2}" ,
2184
+ escapeSuffix )
2185
+ : string . Format ( "{0} like {1}{2}" ,
2200
2186
quotedColName ,
2201
2187
ConvertToParam ( "%" + wildcardArg + "%" ) ,
2202
2188
escapeSuffix ) ;
2203
- }
2204
2189
break ;
2205
2190
case "Substring" :
2206
2191
var startIndex = int . Parse ( args [ 0 ] . ToString ( ) ) + 1 ;
2207
- if ( args . Count == 2 )
2208
- {
2209
- var length = int . Parse ( args [ 1 ] . ToString ( ) ) ;
2210
- statement = GetSubstringSql ( quotedColName , startIndex , length ) ;
2211
- }
2212
- else
2213
- {
2214
- statement = GetSubstringSql ( quotedColName , startIndex ) ;
2215
- }
2192
+ statement = args . Count == 2
2193
+ ? GetSubstringSql ( quotedColName , startIndex , int . Parse ( args [ 1 ] . ToString ( ) ) )
2194
+ : GetSubstringSql ( quotedColName , startIndex ) ;
2216
2195
break ;
2217
2196
case "ToString" :
2218
- if ( m . Object . Type == typeof ( string ) )
2219
- {
2220
- statement = string . Format ( "({0})" , quotedColName ) ;
2221
- }
2222
- else
2223
- {
2224
- statement = string . Format ( "cast({0} as varchar(1000))" , quotedColName ) ;
2225
- }
2197
+ statement = m . Object . Type == typeof ( string )
2198
+ ? string . Format ( "({0})" , quotedColName )
2199
+ : ToCast ( quotedColName . ToString ( ) ) ;
2226
2200
break ;
2227
2201
default :
2228
2202
throw new NotSupportedException ( ) ;
2229
2203
}
2230
2204
return new PartialSqlString ( statement ) ;
2231
2205
}
2232
2206
2207
+ protected virtual string ToCast ( string quotedColName )
2208
+ {
2209
+ return string . Format ( "cast({0} as varchar(1000))" , quotedColName ) ;
2210
+ }
2211
+
2233
2212
public virtual string GetSubstringSql ( object quotedColumn , int startIndex , int ? length = null )
2234
2213
{
2235
2214
return length != null
0 commit comments