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 7865263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:02:02+00:00 2026-06-03T00:02:02+00:00

Possible Duplicate: The query results cannot be enumerated more than once? I am using

  • 0

Possible Duplicate:
The query results cannot be enumerated more than once?

I am using entity framework to select and return a group of entities form my database using a stored procedure.

var results = dataContext.loadData(testargument);

I want to count this returned set (to make sure only 1 record is returned and then take the first item in this list.

if(results.Count() == 1)
{
    ReturnedEntity entity = results.First();
}

However when I do this call I get the error “The result of a query cannot be enumerated more than once.” Does anyone know how I can do this correctly? I assume that calling the Count() method is changing the data and am not sure if I need to put it back into a list before calling the first() method. I have tried results.ToList().First() but get the same error.

In addition I notice that if I call the First() method on an empty set I get an error which is why I am trying to make sure there is only 1 record returned.

  • 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-06-03T00:02:03+00:00Added an answer on June 3, 2026 at 12:02 am

    You can avoid this problem using ToList(). Becuase then when you have the list loaded in your memory you can do whatever you want. But I reccomend you use FirstOrDefault().

    var results = dataContext.loadData(testargument).ToList();
    

    And

    ReturnedEntity entity = results.FirstOrDefault();
    

    Or

    if(results.Length == 1)
        ReturnedEntity entity = results.First();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: mysql: Using LIMIT within GROUP BY to get N results per group?
Possible Duplicate: PHP MySQL multiple search query using option / select HTML form tags
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
Possible Duplicate: Mysql single query join 3 table and get all the results Hi
Possible Duplicate: Select top 1 result using JPA i wish to fetch top 10
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
Possible Duplicate: linq to sql recursive query I got stuck with having to build
Possible Duplicate: Parse query string into an array What's the fastest method , to
Possible Duplicate: highlighting search results in php/mysql I am doing a search with a

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.