none
Adding a table in already deployed EF project? RRS feed

  • Question

  • So, I recently built a project that's been deployed for a few months, and has a decent amount of data.  Now (inevitably I guess) I get an inquiry to add some functionality that's going to require a new table.  I don't have any problem adding in my development environment and updating my EF model, but I've been fortunate inasmuch as I've never had to add a table to an already deployed (and populated) db before.

    As always, I'm deeply indebted for any help or suggestions...

    Wednesday, December 26, 2012 4:04 PM

All replies

  • Hi Paul,

    Welcome to the MSDN forum.

    According to your description, it seems you are using database first or model first, and you added the new table into entity data model and update database from current model. Is that right?

    Do you mean you want to add the new table in entity data model without adding it in database?

    If so, I think it is not possible. If you add a new table in entity data model without updating, the entity information only exists in the CSDL part of edmx file.  However, EF requires the corresponding information to the new entity should exists in SSDL part and mapping information should exists in MSL part. If you add these information manually, I am afraid you are not able to use this new table in EF. Since all the queries in EF are translated to SQL by EF, if you manipulate a table which doesn’t exists in database, the error would be thrown.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 7:18 AM
  • Hi Alexander,

    Thanks for your reply.  No, that's not quite my situation.  I have yet to add the table locally, but I understand of course how to do that and update my data model in VS.  But, I'm unsure of how to deploy that additional table to my host, especially without affecting my existing data.  I originally created the db by running a backup on the host...

    Thanks again for your interest!

    Thursday, December 27, 2012 2:33 PM
  • Hi Paul,

    Sounds like this is more of a general database versioning problem. How do you evolve your development database and then deploy the changes since the last deployment to your production environment.

    At its most fundamental level you need to have a SQL script to modify your production database to match what it should look like, add your new table in this case. You then execute that against your prod database when you are doing your upgrade.

    In practice it is usually far more complicated than that.

    So the answer to your question, as far as I understand it, isn't really about EF but how to evolve the database that you are using EF to connect to. The answer to that question really depends on your environment and how complicated a setup you need.

    In terms of what EF provides to help support this, you can use Code First Migrations or IIRC the designer allows you to generate sql somewhere in the right click menu. If you want to explain the environment more and how you go about developing and pushing changes to prod it might help to give some more guidance.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Wednesday, January 2, 2013 9:31 PM
    Moderator
  • Paul,

    What I do is run the same Table Create SQL in SQL Server Management Studio on the host system.


    Dan Randolph - My Code Samples List

    Wednesday, January 2, 2013 10:27 PM
  • Hi Dan and Glenn...

    So, I'm sorry I haven't explained myself well, but in spite of that I think we're getting close to the answer I was hoping for ;) 

    I need to add a table to my project, and can of course do that and update my EF model.  But I've never added a table to a remotely hosted SQL Server and need to know A) how to do so without overwriting existing tables (I've only done it in the past by running backup against the remote host) and B) do I need to do anything to my EF model or will the newly created remote SQL table work OK with it?

    Thursday, January 3, 2013 12:38 AM