4

I'm using the System.Linq.Dynamic library DynamicQuery as part of a solution using EF on .NET Framework 4.0 to try and convert a Nullable (int?) to String within the Select similar to:

query= "new(Convert.ToString(columnName) as stringColumn)";
IQueryable result = queryable.Select(query, parameters[]);

How do I get the Expression.Call to work and return the string equivalent of a Nullable column?

Thanks, John


Things I've tried:

  1. I've tried sending Convert.ToString(columnName) as part of the query:

System.ArgumentException: Expression of type 'System.Nullable1[System.Int32]' cannot be used for parameter of type 'System.Object' of method 'System.String ToString(System.Object)' at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi) at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection1& arguments) at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments) at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments) at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in c:\Projects\DynamicQuery.cs:line 3461

  1. I've tried using (columnName).toString() and receive the following:

System.Linq.Dynamic.ParseException: Methods on type 'Int32?' are not accessible at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in c:\Projects\DynamicQuery.cs:line 3453

1
  • were you able to solve this?
    – FabioG
    Aug 7, 2015 at 11:42

2 Answers 2

1
query = "new(Convert.ToString((int?)columnName))";
1
  • Doesn't work in the query string. No property or field 'int' exists in type 'DynamicClass1'.
    – Cynicszm
    Mar 12, 2014 at 14:00
0

Try to use

query = "new(Convert.ToString(Int32(columnName)))"

or

query = "new((Int32(columnName)).ToString())"
1
  • Please explain your answer
    – unicorn2
    Jul 4, 2017 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.