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

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
EDIT: My mistake was that I had a go after the first select statement
The below code makes application freeze when changing focus from Edit1 to Edit2 after
When Proguard optimize my application, it seams that all calls to Object#wait() are being
I've been working a Django-CMS plugin that uses the Flickr API, and after much
After a hard reset of my laptop that freezed after a git commit, I
Edit note: After a seemingly enourmous amount of bad feedback MS got from their
I'm trying to immediately set a row to Edit mode after it is created.
Possible Duplicate: Saving changes after table edit in SQL Server Management Studio I need
oo design basics here... Edit: To clarify after first answer - I'm not asking

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.