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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:36:13+00:00 2026-05-23T12:36:13+00:00

I’m building an application against a legacy database that stores lookup values in a

  • 0

I’m building an application against a legacy database that stores lookup values in a generic table (actually it’s held in four different tables.) This means that the entity tables store the “id” of the lookup value and the metadata tables hold the “description” of this value.

The metadata tables are broken down like this:

  • TableInfo
  • ColumnInfo
  • BusinessInfo
  • LookupDescriptionInfo

To get the lookup description, you join all four tables and specify the table name, column name, and lookup id. The lookup description info table contains two columns—one for text values and one for numeric values.

I’d like to have a separate class for each lookup type (e.g., my Widget class would have a many-to-one relationship with “WidgetType” based on the Widget.WidgetTypeId value.) What are some strategies for accomplishing this? The data model is used by over 1000 RPG programs, so it can’t be altered.

  • 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-23T12:36:14+00:00Added an answer on May 23, 2026 at 12:36 pm

    I have had almost exactly the same problem as you and have found the following solutions viable.

    Create SQL View

    -- I'm guessing at the table join structure here
    create view LookupView
    as
    select t.TableName, 
       ci.ColumnName,
       bi.Id, --This ID column needs to be the one used as the FK from other tables
       bi.*, --Or whatever columns you need
       coalesce(di.TextDescription, di.NumericDescription) as Description
    from TableInfo t
    join ColumnInfo ci on t.Id=ci.TableId
    join BusinessInfo bi on bi.Id=ci.BusinessId
    join LookupDescriptionInfo di on di.id=ci.id
    

    Create base Lookup Class

    public class Lookup {
        public virtual string Tablename {get; set;}
        public virtual string ColumnName {get; set;}
        public virtual string Description {get; set;}
        public virtual int Id {get; set;}
        //Other BusinessInfo properties
    }
    

    Create a inherited LookupClass

    public class ArmourLookup : Lookup{}
    

    Use the ArmourLookup class on your business objects.

    public class HeroArmour{
        //Usual properties etc....
        public virtual ArmourLookup Lookup {get; set;}
    }
    

    Create a subclass discriminated mapping set

    public class LookupMap : ClassMap<Lookup> {
        public LookupMap(){
            Id(x=>x.Id).GeneratedBy.Assigned(); //Needs to be a unique ID
            Map(x=>x.Tablename);
            Map(x=>x.ColumnName);
            Map(x=>x.Description);
            //Business Info property mappings here
            Table("LookupView")
            DiscriminateSubClassesOnColumn<string>("ColumnName");
            ReadOnly();
        }
    }
    
    public class ArmourLookupMap : SubClassMap<ArmourLookup> {
        public ArmourLookupMap (){
            DiscriminatorValue("ArmourColumn");
        }
    }
    

    Now you can repeat the subclass mapping for every column you have creating new types with ease. The issue here is that you cannot update or insert new lookups into the View so you are in a read-only mode.

    This method uses the column name as the discriminator so does away with the table name but if you have duplicate column names in your lookup table you could create a base lookup class for every table and specify a filter condition in the mapping.


    Another potential solution could be to use Enums generated by T4 templates from the lookup tables. Although this also is a read only approach.


    You could also map out each lookup table as a class and use the discriminator pattern to get different types from the ColumnInfo table.

    public class TableInfo {
         public virtual int Id {get; set;} 
         public virtual string Tablename {get; set;}
         public IList<ColumnInfo> Columns {get; set;}
    }
    
    public class ColumnInfo {
       public virtual int Id {get; set;}
       public virtual TableInfo TableInfo {get; set;}
       public virtual BusinessInfo BusinessInfo {get; set;}
       public virtual LookupDescriptionInfo LookupDescriptionInfo {get; set;}
       //Other properties
    }
    
    public class ArmourInfoColumn : ColumnInfo {
        //In the mapping you would discriminate on the columnname column.
    }
    
    etc...
    

    Again optionally you can decide to discriminate out some XTable classes if you have duplicate column names in the column info table but different tableid’s.

    You could also discriminate on the ColumnType (numeric or text) and subclass the LookupDescription class to use different columns for the “Description” property.

    If you could provide your table structure and some sample values I could flesh these ideas out more for you.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

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.