@@ -331,26 +331,28 @@ private Expression<Func<T, bool>> ApplyGenericSearch
331331
332332 if ( prop . PropertyType == typeof ( DateTime ) || prop . PropertyType == typeof ( Nullable < DateTime > ) )
333333 {
334+
335+ var date = Expression . Convert ( propExp , typeof ( Nullable < DateTime > ) ) ;
334336 //Only way to get a number for date part
335337 var datePart = typeof ( SqlFunctions ) . GetMethod ( "DatePart" , new Type [ ] { typeof ( string ) , typeof ( Nullable < DateTime > ) } ) ;
336338 //get day of month and year which are already strings
337339 var dateName = typeof ( SqlFunctions ) . GetMethod ( "DateName" , new Type [ ] { typeof ( string ) , typeof ( Nullable < DateTime > ) } ) ;
338340 //Call to get month part
339- var month = Expression . Call ( datePart , Expression . Constant ( "m" ) , propExp ) ;
341+ var month = Expression . Call ( datePart , Expression . Constant ( "m" ) , date ) ;
340342 //Convert to double
341343 var toDouble = Expression . Convert ( month , typeof ( Nullable < double > ) ) ;
342344 //convert to string
343345 var monthPartToString = typeof ( SqlFunctions ) . GetMethod ( "StringConvert" , new Type [ ] { typeof ( Nullable < double > ) } ) ;
344346 //now all three numerical parts of date as string
345- var monthPart = Expression . Call ( monthPartToString , toDouble ) ;
346- var dayPart = Expression . Call ( dateName , Expression . Constant ( "d" ) , propExp ) ;
347- var yearPart = Expression . Call ( dateName , Expression . Constant ( "yy" ) , propExp ) ;
348- var conCat4 = typeof ( string ) . GetMethod ( "Concat" , new Type [ ] { typeof ( string ) , typeof ( string ) , typeof ( string ) , typeof ( string ) } ) ;
347+ var monthPart = Expression . Call ( monthPartToString , toDouble ) ;
348+ var dayPart = Expression . Call ( dateName , Expression . Constant ( "d" ) , date ) ;
349+ var yearPart = Expression . Call ( dateName , Expression . Constant ( "yy" ) , date ) ;
350+ var conCat4 = typeof ( string ) . GetMethod ( "Concat" , new Type [ ] { typeof ( string ) , typeof ( string ) , typeof ( string ) , typeof ( string ) } ) ;
349351 var conCat2 = typeof ( string ) . GetMethod ( "Concat" , new Type [ ] { typeof ( string ) , typeof ( string ) } ) ;
350352 var delim = Expression . Constant ( "/" ) ;
351353 stringProp = Expression . Call ( conCat2 ,
352354 Expression . Call ( conCat4 , monthPart , delim , dayPart , delim ) , yearPart ) ;
353-
355+
354356 }
355357
356358 if ( prop . PropertyType == typeof ( string ) )
0 commit comments