@@ -333,11 +333,18 @@ private PendingProjectsNode VisitInputWithBinding(DbExpression expression, strin
333333 input . Projection = new CommaSeparatedExpression ( ) ;
334334
335335 DbNewInstanceExpression projection = ( DbNewInstanceExpression ) exp . Projection ;
336- RowType rowType = projection . ResultType . EdmType as RowType ;
336+ RowType rowType = ( RowType ) projection . ResultType . EdmType ;
337337 for ( int i = 0 ; i < rowType . Properties . Count && i < projection . Arguments . Count ; ++ i )
338338 {
339- EdmProperty prop = rowType . Properties [ i ] ;
340- input . Projection . Arguments . Add ( new ColumnExpression ( projection . Arguments [ i ] . Accept ( this ) , prop . Name , prop . TypeUsage ) ) ;
339+ var prop = rowType . Properties [ i ] ;
340+ var argument = projection . Arguments [ i ] . Accept ( this ) ;
341+ var constantArgument = projection . Arguments [ i ] as DbConstantExpression ;
342+ if ( constantArgument != null && constantArgument . Value is string )
343+ {
344+ argument = new CastExpression ( argument , "varchar" ) ;
345+ }
346+
347+ input . Projection . Arguments . Add ( new ColumnExpression ( argument , prop . Name , prop . TypeUsage ) ) ;
341348 }
342349
343350 if ( enterScope ) LeaveExpression ( child ) ;
@@ -1210,6 +1217,17 @@ private VisitedExpression VisitFunction(EdmFunction function, IList<DbExpression
12101217
12111218 return new CastExpression ( args [ 0 ] . Accept ( this ) , "tsquery" ) ;
12121219 }
1220+ else if ( functionName == "cast" )
1221+ {
1222+ if ( args . Count != 2 )
1223+ throw new ArgumentException ( "Invalid number of arguments. Expected 2." , "args" ) ;
1224+
1225+ var typeNameExpression = args [ 1 ] as DbConstantExpression ;
1226+ if ( typeNameExpression == null )
1227+ throw new NotSupportedException ( "cast type name argument must be a constant expression." ) ;
1228+
1229+ return new CastExpression ( args [ 0 ] . Accept ( this ) , typeNameExpression . Value . ToString ( ) ) ;
1230+ }
12131231 }
12141232
12151233 var customFuncCall = new FunctionExpression (
0 commit comments