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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:26:04+00:00 2026-05-13T08:26:04+00:00

I have an application where a multiple shops will share the data. There is

  • 0

I have an application where a multiple shops will share the data. There is an Options table that defines various program options. I have a varchar column that defines the value type, int, bool, Guid, string, etc. There are two tables that define the option values, one for system wide options and one for local options. The base Options table defines if the local option can be selected before the system wide option. The Shop and Global option tables are basically the same structure except the ShopOption table has a ShopId FK for the shop the record belongs to. Each of these tables store the option values as varchar although the string may represent an integer, Guid, bool, or may actually be a string. I need to show a form with a tab for the local option, a tab the global option, and a tab to specify if the shop can overide the global. What I am not doing right is to get an option entity and get the value as the type it should be.

For instance:
GetOption(SessionTimeout) should return an Option entity and the value should be an integer type.
GetOption(DefaultCustomer) should return an Option entity and the value should be a Guid type.

I am searching for an answer using design patterns, and think a factory pattern may be what I want, but I am just not getting it.

  • 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-13T08:26:04+00:00Added an answer on May 13, 2026 at 8:26 am

    There are two solutions, each having its merit and its drawbacks :

    Option 1 : Genericity

    a system wide option table, defined like this :

    Create table tbGlobalOptions
    (
    OptionName Varchar(255) Identity,
    OptionValue Varchar(255),
    OptionType varchar(255)
    isLocked bit --this indicated the value cannot be overridden by the user. 
    )
    

    And an user options table :

    Create table tbUserOptions
    (
    OptionName varchar(255)
    UserID bigint,
    OptionValue varchar(255),
    Active bit
    )
    -- extra fields for logging omitted 
    -- keys omitted 
    

    The code contains an enum matching the OptionName column, so parsing Options from the code is trivial.

    Cons :

    • type safety can only be implemented using constraints or triggers (which is clearly harder to maintains than column types)
    • it’s harder to use the stored options directly from the database (as the parsing logic lives in the application code)
    • retrieving all the options for a specific user is more costly (you cannot just select the user row)

    Option 2 : Specialization (and strong typing)

    A strongly typed option table containing one column per option

    Create table tbOptions
    (
    UserId bigint, -- 0 for global defaults
    Option1 int,
    Option2 varchar(max)
    Option3 int,
    ...
    Option426 bit
    )
    

    Type safety is clearly a good thing, but here it has a huge cost :

    • adding a new option requires a schema change
    • the stored procedures used to update the table will contain a lot of duplicated code, as the logic (eg the isLocked mechanism, or some extra logging you might want to add) must be repeated over and over for each field. This is how you end up with stored procedures containing 1500 arguments.
    • This solution doesn’t scale well, as a table cannot have an unlimited number of columns (see max values for SQL Server 2008 here for example).

    If you have 5 options and if this number is likely to stay the same over time, the second solution has its merits.

    If on the other hand you plan to end up with thousands of options, this sound like a no-brainer for me : go for genericity !


    In your application code, your problem is quite easily solved using a generic method :

    OptionEntity<T> GetOptions<T>(string OptionName, T defaultvalue);
    

    Edit to answer Bryan’s comment below :

    And yes, if there are 10000 values to store, there will be 10000 columns. That is true for every single table you will ever write. There is nothing special about an option table. Nothing.

    This all depends on the level of abstraction we chose. How would you store a chess board position for example? You can clearly use a 64 columns table (64 values -> 64 columns)
    or you can use a design with 4 columns only (game id, x, y, contents). Don’t you think both can be adequate depending on the situation?

    In this specific case, if options can be created on the fly, or if their numbers is expected to grow exponentially, those options are, to a certain extent, just another type of data. And you don’t want to store data in your schema, do you?

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

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the data in the /proc filesystem to… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer Do you still get the error when you use a… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer You can use array_chunk to create a single array comprised… May 14, 2026 at 3:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.