-3

I am getting System.Data.Objects.ObjectResult executing stored proc sp_GetCustSurveys, then I am iterating through the resultset. Inside of the main loop, I would like to create a subset of items (list of items having the same id):

using (MyObject_Surveys _db = new MyObject_Surveys ())
        {
            _db.CommandTimeout = 10000;
            var rawSurveys = _db.sp_GetCustSurveys();
            foreach (var survey in rawSurveys)
            {
               var surveyMultipleLangs = rawSurveys.Where(w => w.Id.Contains("123"));
                        foreach (var itm in surveyMultipleLangs)
                        {
                            var myName = itm.Name;
                            var myLanguage = itm.Language;
                        } 
               ....

When I am iterating through the subset, i am getting error: "query results cannot be enumerated more than once". Please advise. Thank you.

  • what line does it break on? – Sam I am says Reinstate Monica Sep 04 '14 at 17:37
  • 2
    Why do you have an outer `foreach`, you are not doing anything with `survey` from outer foreach, you are just using the `rawSurveys` again. See this question http://stackoverflow.com/questions/5723555/the-result-of-a-query-cannot-be-enumerated-more-than-once – Habib Sep 04 '14 at 17:37
  • I have new object for each servey which I am populating with survey properties. I just skipped the code. My problem is the subset. How I can create it? any operation with "surveyMultipleLangs" (looping, converting to list..) forces enumeration which causing error. – Peter Camenzind Sep 04 '14 at 17:44
  • Ok, got it. All I need is to materialize my ObjectResult – Peter Camenzind Sep 05 '14 at 16:33

1 Answers1

0

Ok, got it. All I need is to materialize my ObjectResult for being able to query it again: var rawSurveys = _db.sp_GetCustSurveys().toList(); It seems like it works.