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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:16:49+00:00 2026-06-04T23:16:49+00:00

I have a small issue with EF. I’m performing a query on a large

  • 0

I have a small issue with EF. I’m performing a query on a large table, and it takes very long. I think I found the cause, but cannot find a solution;

My LINQ query looks like this:

IEnumerable<string> o = (from P in Table where P.ITEMID == itemid && P.IMAGESIZE == size select P.PATH);
return o.Any() ? o.FirstOrDefault() : null;

I expect this to produce a SQL query with a where clause, but what it actually produces is this:

SELECT 
[Extent1].[ITEMID] AS [ITEMID], 
[Extent1].........
snap 10 columns
FROM [dbo].[TABLE] AS [Extent1]

The where clause and select (I try to select only one column) are executed after enumeration. What I want it to do is to produce a SQL query with the where clause and select only one column.

What am I doing wrong?

  • 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-04T23:16:50+00:00Added an answer on June 4, 2026 at 11:16 pm

    Since you are creating an IEnumerable<string> type of object, EF runs this query in the first line. Then Any() or FirstOrDefault() are executed in the memory set.
    If you want to “continue” writing linq statements and run the query in the end; just go with IQueryable<T>.

    IQueryable<string> o = (from P in Table where P.ITEMID == itemid && P.IMAGESIZE == size select P.PATH);
    return o.SingleOrDefault();   
    

    but as Ryan Bennett suggested, it is easier to use;

    return Table.Where(p => p.ITEMID == itemid && P.IMAGESIZE == size).SingleOrDefault().PATH;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating Bluetooth custom application, but I have a small issue. When in my
hey guys, i have very small issue please see the code below // this
In my Java application I have found a small performance issue, which is caused
I have a small issue. I can't seem to get the script to recognise
I have a small issue with a method that should save the text contained
I have a small issue(for lack of a better word) with MySQL db. I
i have a small issue which my text field insist to inhert the CSS
I am just new to programming in Unix and have a small issue that
can anyone help, i have a small issue, i have an interface and also
I have run into a small issue in my program. I have a class

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.