2

I am working with AspNetCore and Entity Framework core.

I have made changes to my existing database, and I want these changes to be reflected in my code.
In earlier version of the entity framework, I would do an "Update from database".
I have read a lot about migrations, but they all seem to show me how to do an initial migration.

So how can i update my code base with changes in my database?

Axel Andersen
  • 330
  • 4
  • 14
  • EF Core is [code first](http://www.entityframeworktutorial.net/code-first/what-is-code-first.aspx). You change your models first and the migrations will provide a mechanism to update the database. You can do code first from an existing database where you reverse engineer to get the initial code, but then you would switch to migrations moving forward. – Steve Greene Jul 04 '17 at 19:24
  • 1
    Really, no chance of doing this like before? Thats a step back if you ask me. – Axel Andersen Jul 04 '17 at 19:57
  • I came from a database background and resisted at first, but now it makes much more sense to me and I rarely run into anything I can't do code first. No reason you couldn't do EF6 in .NET Core - many are. – Steve Greene Jul 04 '17 at 23:21
  • Dont you find it easier to do a proper database design directly on the database, instead of guessing what EF Core will do to your database from the code you wrote? – Axel Andersen Nov 07 '17 at 09:48
  • Maybe as a starting point. Most of my changes after initial release are fairly minor tweaks. As always, it depends on the project. Lot's of [discussion](https://softwareengineering.stackexchange.com/questions/264379/code-first-vs-database-first) here on the issue. – Steve Greene Nov 07 '17 at 14:06
  • If you put an answer I will give it to you – Axel Andersen Nov 07 '17 at 15:27

1 Answers1

3

EF Core does not support the database first model as discussed many places including here and here.

If you follow the code first model with EF Core, you could get initial models by reverse engineering the database as described here. Then you would use migrations to update your database from there on as described here.

If you prefer a data-centric approach you might consider database projects to maintain the schema. You would need to manually keep the models in sync, but you could reverse engineer individual tables to mitigate the issues.

Steve Greene
  • 12,029
  • 1
  • 33
  • 54