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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:47:16+00:00 2026-05-12T18:47:16+00:00

Edit2: After finally being able to profile the two against each other, it appears

  • 0

Edit2:
After finally being able to profile the two against each other, it appears that in my situation .AsQueryable() is slightly faster than Expression.Compile().

Original question:
I have implemented a cache of some database tables (as List<T>) that I need to query with the same Expression<Func<T, bool>> as I would use when querying against the Table<T> itself.

What is the fastest/best way of these:

List<T>.AsQueryable().FirstOrDefault(Expression<Func<T, bool>>)

or

List<T>.FirstOrDefault(Expression<Func<T, bool>>.Compile())

?

Edit:
Changed Where to FirstOrDefault, as that is the method I’m using. I guess I was a little tired when I wrote the question. Will FirstOrDefault examine every item once like Where, or does it actually stop on the first hit (if any)?

  • 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-12T18:47:17+00:00Added an answer on May 12, 2026 at 6:47 pm

    As always, the best way to determine what’s faster is to try it out, however:

    Filtering a List<> using a simple Where will always result in each item being examined once. Without further assumptions such as your list being sorted in a specific order, there’s really no other way, meaning the two versions you give will result in the exact same evaluations of your expression.

    If you’re going to use the same expression multiple times, you could possibly benefit from compiling it and caching the delegate, though the data would have to be small and the expression complex in order for it to make a difference.

    Edit: Going through Queryable could possibly be faster for expressions that does not actually depend on any input at all, such as () => false.

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

Sidebar

Related Questions

I have an application that uses MSWord automation to edit some documents, after they
I have a variable that is not supposed to change its value after it's
The below code makes application freeze when changing focus from Edit1 to Edit2 after
I finally after too much of pondering started my project on googlecode. One of
I've been working a Django-CMS plugin that uses the Flickr API, and after much
I've finally gotten this working after days of struggle. I've got a simple database
After going through tutorials on getting started with Tortoise I am finally starting to
after weeks of having this issue I finally decided to ask for a solution
And now after some work, I finally understand how the KDop bounding volume are
I've finally figured out how to make all my millions of tabs (not that

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.