title: Accessing a Common Code Value Table in Generated EF Models
body: <p>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.).</p>
  
  <p>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.</p>
  
  <p>Here's what a single getter would be that I would have to repeat many times if I were to do it manually:</p>
  
  <pre><code>    public string State
      {
          get
          {
              MyEntityContext c = new MyEntityContext();
              return c.CodeValues.Single(cv =&gt; cv.Id == RecordStatusCdvId).Value;
          }
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>Any help?</p>