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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:01:26+00:00 2026-05-29T06:01:26+00:00

I created a dictionary from a Linq query result as suggested from stackoverflow questions

  • 0

I created a dictionary from a Linq query result as suggested from stackoverflow questions answer: A dictionary where value is an anonymous type in C#

var intToAnon = sourceSequence.ToDictionary(
e => e.Id,
e => new { e.Column, e.Localized });

I have added this new object into my ASP.NET cache. How can I read it from the cache (HttpContext.Current.Cache.Add)? I imagine I need reflection but not sure how to go about it.

Any idea?

Thanks

  • 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-29T06:01:27+00:00Added an answer on May 29, 2026 at 6:01 am

    To retrieve an anonymous type you’ll either need to use reflection or cast-by-example, neither of which are a good idea in this case.

    Instead, either create your own custom type to hold the data, or use one of the built-in Tuple types:

    // dict will be a Dictionary<TId, Tuple<TColumn, TLocalized>>
    // where TId, TColumn and TLocalized are the actual types of those properties
    var dict = sourceSequence.ToDictionary(e => e.Id,
                                           e => Tuple.Create(e.Column, e.Localized));
    Cache["yourCacheKey"] = dict;
    

    Then when you get the object from the cache just cast to the appropriate Tuple type:

    // i'm assuming here that Id is Int32, Column is String, and Localized is Boolean
    var dict = (Dictionary<int, Tuple<string, bool>>)Cache["yourCacheKey"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a small class that loads dictionary items from a plist file. The
i created the following code: Dictionary<string, string> allItemNames = new Dictionary<string, string>(); var productNames
I'm using Enumerable.ToDictionary to create a Dictionary off of a linq call: return (from
I'm trying to use LINQ to create a new dictionary from an existing one,
I am trying to create a dictionary from 2 lists where one list contains
I want to create variables inside a function from a dictionary. Let's say I
Is it possible to create an object from a dictionary in python in such
I am trying to created nested dictionary variable like the below, But I get
I'm a C++ expert, but not at all for C#. I created a Dictionary<string,
I created a class Entry to handle Dictionary entries, but in my main(), I

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.