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

  • Home
  • SEARCH
  • 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 6666579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:50:35+00:00 2026-05-26T02:50:35+00:00

Project info: WPF, PRISM, C# 4.0, WCF, Entity framework, SQL(express) My database contains several

  • 0

Project info: WPF, PRISM, C# 4.0, WCF, Entity framework, SQL(express)

My database contains several “constants” e.g. a person has a classification -> Natural Person (ID = 1) or lawful person (ID = 2).

I want to get these constants out of the DB, and store them in the cache, so they can be used throughout the application, so they aren’t “hard coded”. I know you can store these constants in a static class, but this would only work if these constants don’t change in the DB (and I don’t want to rely on that fact).

My question is: how can I efficiently load these constants out of the DB and put them in my cache?

The following is how I’ve written it now, but it just doesn’t feel right..

using (DetacheringenEntities objectcontext = new DetacheringenEntities())
{
   int natuurlijkPersoonClassificationResult = objectcontext.Classification.Where(c => c.Value == "Natuurlijk Persoon").Select(c => c.ClassificationID).SingleOrDefault();
   int rechtspersoonPersoonClassificationResult = objectcontext.Classification.Where(c => c.Value == "Rechtspersoon").Select(c => c.ClassificationID).SingleOrDefault();

   int klantPersonAgreementRoleResult = objectcontext.PersonAgreementInvolvementRole.Where(p => p.Value == "Klant").Select(p => p.PersonAgreementInvolvementRoleID).SingleOrDefault();  
   ... (about 10 more of these calls)    
}

After getting these out of the DB I put them in my cache:

 DefaultCacheProvider cacheProvider = new DefaultCacheProvider();
 cacheProvider.Set("NatuurlijkPersoon", natuurlijkPersoonClassificationResult, 30);

I make use of a Repository on my caching, so I can also unit test is later.

I’ve tried making a generic methode, but I failed terribly 😛

private int GetDatabaseConstantValue<T>(Expression<Func<T, bool>> expression, DetacheringenEntities context)
{
        int result = context
            .CreateQuery<T>(
            "[" + typeof(T).Name + "]")
            .Where(expression)
            .Select(typeof(T).Name + "ID").FirstOrDefault(); --> This doesn't work (obviously), but I want to select the ID of that table (which is always Tablename + ID).

        return result;
}

Any ideas of how I can solve this problem or make it better?

Thanks for any help!!

PS: Any tips are also appreciated 🙂

  • 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-26T02:50:36+00:00Added an answer on May 26, 2026 at 2:50 am

    Can’t you just build a dictionary?

    var classifications = objectcontext.Classification.ToDictionary(c => c.Value, c => c.ClassificationID);
    

    Then you can retrieve the value:

    classifications["Natuurlijk Persoon"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My project uses a JSON feed to grab info about earthquakes within a specified
Environment info: *Windows Vista *PHP 5.2.9-2 I'm working on a project. Let's say it's
In my A-Level project I have all the record info stored in an MS
Could someone give some info regarding the different character sets within visual studio's project
I have a WPF C# project that I am working on and I have
I prepare a WPF project, where I want to implement a more complex search.
I have built a Wpf-ControLibrary-Project to put some Controls there. In one Control i
Im making a user selection userControl for my WPF C# project. I did make
As we know, in xcode 3, there is a custom location in project info.
I have two Entity (tables) - Employee & Project. An Employee can have multiple

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.