locked
Linq to sql - foreach loop with text data type RRS feed

  • Question

  • I have written a stored procedure that is returning data from sql server. One of the field is text datatype. The procedure works fine.

    Then I got Linq to Sql code that is using the stored procedure. When I debug, I can see it got the data. When I do a foreach loop on the data, the code does not work and I get the following exception - "The query results cannot be enumerated more than once."

    The code works fine if I update the stored procedure not to include the field with text datatype. How can this be fixed.
    Friday, June 3, 2011 7:17 AM

Answers

  • Hi,

    Try to get the result data using ToList() directly.

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Proposed as answer by Alan_chen Monday, June 6, 2011 3:57 AM
    • Marked as answer by Alan_chen Wednesday, June 8, 2011 2:47 AM
    Friday, June 3, 2011 1:52 PM

All replies

  • Hi,

    Try to get the result data using ToList() directly.

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Proposed as answer by Alan_chen Monday, June 6, 2011 3:57 AM
    • Marked as answer by Alan_chen Wednesday, June 8, 2011 2:47 AM
    Friday, June 3, 2011 1:52 PM
  • It worked, however, it's more like a workaround than the solution to the problem.
    Monday, June 6, 2011 3:41 AM