0

Is it possible to create a new table programatically in EF or L2S and load it to its context?

We have this application that requires to create a table at runtime and do some CRUD activities to that table.

Is this possible? If not, any advice?

1 Answer 1

1

You can do this with EF 4 and Code First.

Sign up to request clarification or add additional context in comments.

5 Comments

Code first can create tables base on your model. but it seems you cannot add additional tables or modify them after the database is created.
@mcxiand: That is wrong. Look at step 5 in this demo.
Its still not what im looking for. You can update your table base on your code but you will lose data. It is noted that data migration for that said feature is not yet included on the CTP. “RecreateDatabaseIfModelChanges” behavior isn’t intended for production scenarios where you want to “migrate” existing data from one schema to another. Instead it is designed for development scenarios where you want the database to be quickly and automatically updated for you – without you having to take any manual steps or specify migration rules to do so.
You didn't say that you needed to preserve existing data in your question. The only way to do that is to use the "Database Generation Power Pack" which works with VS 2010 DB deployment projects to do DB schema compares and generate change scripts. It's significantly more complicated, but it works.
Sorry, i forgot to mention that i needed it to preserve the existing data while doing update on table structures. I will try that one. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.