updating changes to dynamic tables with same schemas RRS feed

  • Question

  • I am planning to use Ado.Net Entity Framework and WCF Data Services. In my applications there will be certain tables which will be dynamically created when a user is created.

    Hence there will be a set of tables created which will be specific to a user. However the schema of all tables will be the same. Hence in such cases the dynamically created will not be a part of my entity model.

    I wanted to created a POCO class with the common schema and use the same class for each of the dynamic tables. I wanted to know how i would specify the table name while saving the changes to the dynamic table?



    Saturday, October 20, 2012 6:41 PM


  • Hi Vandana;

    Entity Framework does not support dynamically created tables directly. If you will need to create tables at run time you will need to use EF methods that will execute TSQL statements supplied at run time on the server. The EF commands would be ExecuteStoreCommand and ExecuteStoreQuery methods. These commands are only available on an instance of ObjectContext. If you are using DbContext then you will need to get a reference to its ObjectContext by using the following statement.

    // Where context is a type of ObjectContext and
    // dbContext is of type DbContext
    ObjectContext context = ((IObjectContextAdapter)dbContext).ObjectContext;


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Monday, November 5, 2012 9:37 AM
    Saturday, October 20, 2012 8:20 PM