Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:39:10+00:00 2026-05-25T20:39:10+00:00

This my code. Simplified for readability var query = from p in people select

  • 0

This my code. Simplified for readability

var query = from p in people select p;

// here is the point that probably causes the issue
ObjectResult<int> idsThatMatch = getIdsThatMatchFullTextSearch("andre");
query = from p in query where idsThatMatch.Contains(p.id) select p;

var count = query.Count();
query = query.OrderBy(p => p.id);
var pessoas = query.Skip(90).Take(30).ToList();

I need to read the count before skip/take to get the total amount of records before paging. The count works fine. But at the last line of my excerpt it triggers the exception

The result of a query cannot be enumerated more than once

Why? The count isn’t supposed to enumerate anything by the way. And how can I solve that? Thank you

EDIT

People thought I was using stored procedures but I’m not. Actually I’m using a “select in”. The code is bellow the comment.

EDIT 2

I just tested the above code without the “select in” part and it works fine

EDIT 3

Using this line works:

ObjectResult<int> idsThatMatch = (getIdsThatMatchFullTextSearch("andre");
query = from p in query where idsThatMatch.Contains(p.id) select p).ToArray();

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:39:11+00:00Added an answer on May 25, 2026 at 8:39 pm

    The problem is this line:

    ObjectResult<int> idsThatMatch = getIdsThatMatchFullTextSearch("andre");
    

    This returns ObjectResult not ObjectQuery or IQueryable. Result can be iterated only once. Once you execute your first query with Count you cannot use result anymore and your second query execution will fail because it will try to iterate result again.

    ObjectResult is not processed on database side – it is the result of executed ObjectQuery and one execution can have only one enumeration of result set. It is like cursor to iterate through result set in your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I have this code (which is way simplified from the real code): public interface
This is a simplified partial version of my code to demonstrate the issue: function
I got this code for a parser from this link. http://www.warriorpoint.com/blog/2009/07/19/android-simplified-source-code-for-parsing-and-working-with-xml-data-and-web-services-in-android/ I am getting
Is this code (simplified from a real project) correct? Will the message always print?
I am reading On lisp and encountered this code (I simplified it a bit).
In a code review, I stumbled over this (simplified) code fragment to unregister an
I have code like this (simplified): def outer(): ctr = 0 def inner(): ctr
This question is partly about delegates, and partly about generics. Given the simplified code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.