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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:47:15+00:00 2026-05-13T19:47:15+00:00

Recently I was working on implementing a small snippet that caches my results and

  • 0

Recently I was working on implementing a small snippet that caches my results and the way I was doing it was using a Dictionary as follows:

 private Dictionary<ID, IQueryable<Results>> _simpleCache;

The idea was to search for all the results that have the id specified by ‘ID’ and if the Dictionary contains the key == id, we simply search through the values present in the IQueryable instead of making a database trip.

I was going over this piece of logic this morning and I was thinking about replacing the IQueryable with HashSet as follows:

private Dictionary<ID, HashSet<Results>> _simpleCache;

Is making this change advisable?

  • 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-13T19:47:15+00:00Added an answer on May 13, 2026 at 7:47 pm

    Yes, it is. Generally, IQueryable<T> implies that you are using a data source provider which is queried each time the queryable is enumerated (of course, this isn’t always the case, as you can call AsQueryable extension method on an IEnumerable<T> which will give you an IQueryable<T> implementation over the IEnumerable<T> implementation).

    To that end, storing the IQueryable<Results> in a dictionary doesn’t actually prevent any hits to the data source when you enumerate through it a second time. It will make a request to the data provider every time you enumerate through it.

    Because of this, you typically want to materialize the results on the client side, usually calling the ToList or ToArray extension methods, and then using IEnumerable<Results> or Results[] as the TValue type parameter of your dictionary.

    Note that you could use a HashSet<T> to store your objects, but you have to make sure that you implement IEquatable<T> and override GetHashCode so that the default equality comparer will perform a comparison on the ID instance exposed by the Results type, either that, or you have to provide an IEqualityComparer<T> implementation that will do the same thing. It’s more than likely that you are using designer-generated code, and it will not do this for you, and your objects will have equality determined by reference, not by value.

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

Sidebar

Related Questions

I was recently working on an application that sent and received messages over Ethernet
I am recently working on better indexing concepts. as part of that, I am
I'm recently working on a WPF application that uses the datagrid from the WPF
I was recently working on a project that involving connection to a POP3 Server.
I recently was working with a subversion project that checked out code not only
I recently began working on a large project that contains a huge number of
I recently started working in VS2010 and noticed right away that the font I
I recently started working on a small CMS. I usually develop .NET applications in
Recently working on my company i'm realize that start to having troubles with some
I'm recently working on a semantic web application project using Rowlex. I've reached some

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.