简体   繁体   中英

Entity Framework Core Update Database - Code First Approach Without Migration

I've been searching for a way, it may or may not be supported yet, I guess I'm looking for a concrete answer.

What I've been looking for is the solution for the following requirements:

  • EFCore Code First Approach
  • With existing database table with significant amount of data already in place
  • Add a couple of columns to the said database table by updating my model
  • No migrations through PM Console, just using Context with Fluent Api at application start
  • No database recreation
  • The approach can be: Check a configuration file or some sort, compare it against the version in a version table in database to trigger the update
  • Project templates: Web Api 2, Uwp

If this is supported, is it advisable? If not, why? what are the disadvantages?

In my experience with the projects I was part of, either database first approach or code first but with database recreation.

The steps I have in mind are: - Update the model - Create migration objects - Update config file for db version - At application start, check the config version against version table - If versions do not match call Update() or Migrate() or both, with Migration objects/types as parameters

This is quite opinion based, but here are my comments.

EFCore Code First Approach

Are you aware of limitations of EF Core? It's linq provider cannot do everything EF6 does. differences between EF and EF Core ?

With existing database table with significant amount of data already in place

That's OK.

Add a couple of columns to the said database table by updating my model

This seems standard practice for EF (Core) apps.

No migrations through PM Console, just using Context with Fluent Api at application start

I don't recommend automatic db upgrades because of the risks of the migration done not when you want it. I'd call it accidental-updagrade-database.

No database recreation

I'm not sure what this means, but yes, EF (Core) can work without recreating a db.

The approach can be: Check a configuration file or some sort, compare it against the version in a version table in database to trigger the update

Project templates: Web Api 2, Uwp

The Uwp part seems irrelevant as I assume that all db access will be done via the api app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM