Solved

One I have created an Entity Model, how do I resync with database?

Posted on 2010-09-24
4
253 Views
Last Modified: 2012-06-27
Using Visual Studio 2010 and Entity Framework 4.0, I need to sync up the Entity with the latest database.

I made changes with new tables, etc.  How do I get a new Entity?  Do I delete and recreate?

How do I make sure that I do not lose any of my code?

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 2
4 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 350 total points
ID: 33756929
Hi newbieweb;

To the question, "How do I get a new Entity?", Right click on the Model design surface and from the context menu click on "Update Model from Database". When the Update Wizard is finished loading click on the Add tab to add new tables, views and SP's, click on the Refresh tab to update the current tables in the model with the database new versions of tables, views and SP's, and the Delete tab to delete tables, views and SP's.

To the question, "Do I delete and recreate?" , no see answer above.

To the question, "How do I make sure that I do not lose any of my code?", as long as you have not been modifying the auto-generated code produced by the wizard it will not be lost.

Fernando
0
 
LVL 16

Assisted Solution

by:SriVaddadi
SriVaddadi earned 150 total points
ID: 33757023
You can syn the Entity model from database as below

1. Open the edmx file (right click in the solution explorer)
2. Right click on the empty area and click "Update model from database" or you could do the same thing from Model Browser.

If you have made any changes to the Entity model generated code then you would loose your  changes updating the entity model

To keep your changes when you update the model

1. Create a partial class for the entity you want to modify and add ur code to your partial class instead of modifying the auto generated code.

* DO NOT MODIFY THE AUTO GENERATED CODE. YOU WILL LOOSE THOSE CHANGES
0
 

Author Closing Comment

by:newbieweb
ID: 33757203
Thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33757278
Not a problem, glad I was able to help.  ;=)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question