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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:15:53+00:00 2026-05-25T12:15:53+00:00

Is there any way to alter the underlying database using EF using Code First

  • 0

Is there any way to alter the underlying database using EF using Code First approach?

I have 2 tables which have a static model:
Users and Info1.

I also have another table which Ill call info2.

I would like to be able to add and remove columns from Info2 from the admin section of my website.

My goal is to have a website which can dynamically be altered as you go, adding and removing fields as the user likes, without the user having to know anything about coding.

I’ve considered using a separate database outside of the one specified in the model of my MVC3 project and do straight SQL requests to that instead.

This could also be accomplished by having a table with the dynamically created fields, and another with the data, but this gets messy fast.

Has anyone done anything like this? Is it a bad idea?

  • 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-25T12:15:53+00:00Added an answer on May 25, 2026 at 12:15 pm

    I’d recommend not trying to expand the table horizontally, that’s an operation that you should make a conscious decision to have.

    Instead, I’d recommend that you store the values as name/value pairs. You can have tables that have specific types (let’s say you needed an integer value paired with a key), and then you would select those into a dictionary for the user.

    You’d also have a table which has the keys, if you are concerned about replicating key values.

    For example, you’d have a UserDefinedKey table

    UserDefinedKeyId (int, PK)     Key (varchar(?))
    --------------------------     ----------------
                             1     'My Website'
                             2     'My favorite color'
    

    Then you would have a UserDefinedString table (for string values)

    UserDefinedStringId  UserId     UserDefinedKeyId  Value
    (int, PK)            (int, FK)  (int, FK)         (varchar(max))
    -------------------  ---------  ----------------  --------------
                      1          1                 1  'http://stackoverflow.com'
                      2          1                 2  'Blue'
                      3          2                 2  'Red'
    

    You’d probably want to place a unique index on the UserId and UserDefinedKeyId fields to prevent people from entering multiple values for the same key (if you want that, have a separate table without the unique constraint).

    Then, when you want to add a value for users, you add it to the UserDefinedKey table, and then drive your logic off that table and the other tables which hold the values.

    Another benefit of storing the values vertically is that you aren’t wasting space for columns with values that aren’t being used by all users.

    For example, assuming you take the approach of modifying the table, for the attributes above, you would get:

    UserId  WebSite                   Color
    ------  -------                   -----
         1  http://stackoverflow.com  Blue
         2  (null)                    Red
    

    Now let’s say a third user comes along, and adds a Favorite Sports Team value, and they are the only one who uses it, the table then looks like:

    UserId  WebSite                   Color  FavoriteSportsTeam
    ------  -------                   -----  ------------------
         1  http://stackoverflow.com  Blue   (null)
         2  (null)                    Red    (null)
         3  (null)                    (null) Yankees
    

    As the number of users and attributes grows, the amount of sparse data that you have will increase dramatically.

    Now, assuming you are using SQL Server 2008, you could use sparse columns, if you don’t, your table is going to get huge but not have much data.

    Also, using sparse columns doesn’t take away from the fact that it’s pretty dirty to use data definition language (DDL) to change the schema on the fly.

    Additionally, Entity Framework isn’t going to be able to adapt it’s object model to account for the new attributes; every time you have an attribute added, you will have to go and add the attribute to your object model, recompile, and redeploy.

    With a vertical approach, it takes more work, granted, but it will be infinitely flexible, as well as utilize your database space more efficiently.

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

Sidebar

Related Questions

Is there any way to massively alter primary keys(uid) to all tables with no
Is there any way to alter my Model properties from a javascript function inside
Is there any way, given a function passed as a parameter, to alter its
Is there any way to debug what is going on after my .NET code
Is there any way to disable entire form using jQuery after submission?
Is there any way to check whether a file is locked without using a
iI there any way to add a GUI component to an application which is
Is there any way to alter the behavior of Url.Content rendering mechanism so that
I have written an application which is using NHibernate to provide the underlying object
While data frame columns must have the same number rows, is there any way

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.