0

I am new to Entity Framework. I have created an EF Model and successfully added some tables and relation. Then I Clicked Generate Database from Model and My DB has been updated. Then I renamed some columns and I don't know how to revert or apply the changes. And Update Model from database does not seems to work because the columns names are different yet.

I need to graphically sync DB with Model. I prefer the model data rather than db data.

Thanks in advance.

2 Answers 2

3

You might want to look into the Code-First approach of Entity Framework. Using that approach you'll define your model in your code, and when changing anything you can create a Migration which allows you to up- and down-grade the DB to a specific version from the package manager console (or just create the respective SQL scripts).

For more information on this subject please see this article on MSDN

Note that you can also reverse engineer the code first model from an existing database (see 3. Reverse Engineer Model in this MSDN article), and then enable migrations for that model (see Step 2: Enable Migrations in this MSDN article)

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

1 Comment

Thank you very much. I can't up vote because of my low reputation.
0

What I do when I make "updates" is do it on both sides manually, in db and then in model (by right click properties) if the change is small. If adding a "new" table I drag it over to model from db server connections panel.

The alternative I've seen others prefer to use in this cases is to stay away from Entity Framework and use Dapper where you pass queries to it and it handles the rest.

Dapper (Wins!) vs Entity Framework vs ADO.NET Performance Benchmarking

Comments

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.