Solved

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

Posted on 2010-09-24
4
250 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 62

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 62

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now