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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:04:29+00:00 2026-06-06T21:04:29+00:00

there has been quite bit of discussion on this topic ( Modifying an Entity

  • 0

there has been quite bit of discussion on this topic ( Modifying an Entity Framework Model at Run-Time), but so far I haven’t been able to find a nice solution to the problem. We currently have a model built with EF 4.0 and need to allow customers to add custom fields to various tables. We have currently solved the problem with a few generic tables that describe the new properties, but we’re finding that the solution is not performing well.

Does anyone know of a good way to dynamically add columns to the database and also update the ORM to reflect that at run-time?

  • 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-06-06T21:04:30+00:00Added an answer on June 6, 2026 at 9:04 pm

    There is no good, nice or manageable way to update EF at runtime to reflect changes in the database. If you really have a database which must change at runtime EF is not good tool for you. EF is strongly typed – every change to database must be reflected not only in mapping but also in entity classes used for loading and persisting data.

    Changing entity classes at runtime always goes to area of emitting IL code at runtime. If you pass the process of creating dynamic assembly with dynamic module and dynamic entity types you will face a lot of new challenges:

    • You will not change your existing types – you will generate a new type every time the user adds or removes some property.
    • A new type generation brings a new performance cost for rebuilding context’s metadata workspace. You must also make sure that this is correctly synchronized if you use it on a server. Another problem is that all existing instances of the old type (before adding or removing property) are now unknown to new instances of EF context and cannot be persisted. If you want to persist them as well you need EF context instances with old metadata workspace as well.
    • A lot of your code will probably use dynamic instead of real type = no compile time checking. Inheritance and interfaces will not be useful when interacting directly with EF because inheritance must be mapped (you don’t want it) and interfaces are not accepted by EF.
    • The new type is unknown at design time – you cannot use it for design time code and compilation.
    • EF doesn’t like dynamic or ExpandoObject because it uses reflection for mapping -> at runtime your dynamic instance must be correct type otherwise reflection will not work.
    • How to write queries for dynamic type? The query always starts at generic instance of DbSet or ObjectSet created for concrete type – you must be able to make those instances dynamically as well. Generic argument must be a type mapped to current context – dynamic will not help in this case because it is not a mapped type.
    • .NET has a nice behavior for this case. It cannot unload assembly. So every time you generate a new type you will have an old time loaded as well.

    Do you still want to change EF at runtime? Your current approach is correct one. Simply tune it for better performance but beware that these requirements always come with performance costs – especially with EF.

    Alternatively use the last approach mentioned with linked table – fixed number of predefined custom fields directly in the main entity.

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

Sidebar

Related Questions

I know this question has been asked several times, but I can't quite seem
Hey all. Something which has been bugging me quite a bit recently is this
There has been similar questions asked (and answered), but never really together, and I
In the Zend Framework Quickstart , there has been a change from models that
Has there been discussion around how to resolve equivalent openids? Meaning, I personally have
There was this problem that has been asked about implementing a load byte into
You would think this one has been asked before but I cant find it.
This problem has been afflicting me for quite a while and it's been really
This has been asked before (question no. 308581) , but that particular question and
This has been bugging me for about 4 hours, so I thought it's time

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.