Dynamic Linq issue - ToArray is not defined RRS feed

  • Question

  • Hi,

    I'm facing an issue in the Dynamic Linq,

    I can't convert it into array, I mean, I built my own dynamic linq query and tried to set the query result into an array of a spesifc contract, as below:

    var Symbols = contractMediator.QueryContracts<ISymbols>(); var query = Symbols.AsQueryable<ISymbols>() .Select("new(" + select + ")") .Where(whereClause); if (!query.Any()) return null;

    else { ISymbols[] testResults = query.ToArray<ISymbols>(); object[] testResultsArray = new object[query.Count()]; for (int i = 0; i < testResultsArray.Length; i++) { testResultsArray[i] = (object)(new SymbolsContractWrapper(testResults[i])); } return testResultsArray;


    In the above code, I the ".ToArray<ISymbols>()" is not defined:

    Note: ISymbols is an Entity framework contract

    But when I use a regual Linq query (not dynamic), the ToArray become defined and works fine.

    Can you please help me solev this issue?



    • Edited by Nadim2522 Wednesday, April 10, 2013 12:58 PM
    Wednesday, April 10, 2013 12:57 PM


  • Hi Nadeem,

    Dynamic LINQ doesn't provide a generic Select method. The non-generic method actually returns an IQueryable.

    public static IQueryable Select(this IQueryable source, string selector, params object[] values);

    System.Linq only provides the ToArray extension method to generic IEnumerable<T>. If you want to get the list of the query, you can try to use foreach statement to loop IQueryable and initialize the array.

    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 12, 2013 1:55 AM