none
Dynamic Creation of Table in EF4 and working with it RRS feed

  • Question

  • Lets say i want to create a table called Customer-orders dynamically like if i want each customer to has its own Table at run-time and then work with it normally in EF4.

    i`m using Code-first Approach with POCO.

    is that possible in EF4 , any idea how to accomplish that ?

    thanks in advance for any tips or info that direct me to accomplish this...

    Wednesday, June 22, 2011 5:32 PM

All replies

  • Hi ZeusSE,

    Welcome!

    I'm not very clear about your requirements, each customer has its own Table, If there are 300 customers, there should be 300 tables(order) for the customers, right?

    But I don't think this design is make sense. We can use foriegn key to navigate the Customer and Orders tables. If your POCO changes and the database also changes, it will drop all data, one way to do this is to run sql command to create a table. If I misunderstood, please feel free to let me know.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 23, 2011 7:58 AM
    Moderator
  • thank you for your reply Alan

    I understand what your saying completely, but i cant change the design i choose the design for many reasons,

    in my system its not customers and orders i was just giving an example, in my system its protocols and connections wont pass 10 but have to be created dynamically. i just didn't wanna explain the whole thing so i gave an example.

    so i really wanna know if its possible to create table dynamically and update the model with the new entity. if its possible can you give me a simple example please ?

     

    thanks in advance for your help.

     

    Thursday, June 23, 2011 8:58 AM
  • I am interested in the answer to this question also.  I am not doing exactly the same thing as the original poster, but I do have the following related situation to deal with...

    User has our software, which expects the database schema to contain a single table with a single field.

    Our company enhances the software with new features which require additional fields to be added to the existing table.  (Another possibility is that the new features require additional tables that don't already exist in the old schema)

    How can EF be used to update the users' existing databases to add fields to existing tables and/or add new tables?  This must be done without dropping any existing tables. 

    The above is a very simple example of the problem.  In reality, our customers will have databases with hundreds or thousands of tables and vast amounts of data.

     

    Thanks

    Thursday, June 23, 2011 2:33 PM