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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:57:33+00:00 2026-05-23T13:57:33+00:00

I have a database that uses a custom model for recording lookup valus (i.e.

  • 0

I have a database that uses a custom model for recording lookup valus (i.e. states, types, etc.). So across all of the database tables, there are various columns called something like state_cdv_id which would store an integer and reference the code_value table to get that state’s value (i.e. “CA”, “AK”, etc.).

I would like to map my EF model so that I can access the code values for all of these fields, and I don’t want to have to do it manually in partial classes for EVERY entity… that’s a lot of repetition. So I want to be able to access my code values like: MyPerson.State and get back the string “CA” for example.

Here’s what a single getter would be that I would have to repeat many times if I were to do it manually:

    public string State
    {
        get
        {
            MyEntityContext c = new MyEntityContext();
            return c.CodeValues.Single(cv => cv.Id == RecordStatusCdvId).Value;
        }
    }

I don’t know what the best approach would be: change the T4 templates, add property attributes to certain fields and then programmatically add a getting to those, or something else.

Any help?

  • 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-23T13:57:33+00:00Added an answer on May 23, 2026 at 1:57 pm

    If there is a 1:1 relationship between the entity and the code_value table the entity should already have a State property, which by default which will be null by default, you could then fill it in by using an Include on your DB queries:

    var foo = context.MyEntities.Include( x => x.State);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF desktop application that uses a custom database for storage. I
We have a sharepoint based application that uses a custom database for storing metadata/files
I want have a single database that uses InnoDB tables instead of myISAM tables
I have a desktop (winforms) application that uses a Firebird database as a data
I have a simple app that uses an SQL Express 2005 database. When the
I have to support an application that uses an access database. My development machine
I have a Dynamic Data Entities Web Application that uses a database with GUIDs
I know that Open Office Database uses a java database backend. Does anyone have
I have a SQL Server 2008 database that uses a default schema called Arxame.
I have a Rails app that uses a lot of custom statistics code 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.