How to apply new changes to current database in code fist EF core? - .net-core

I have a project that coded with DotNet Core code first.
Now, there is a lot of real data on the database and i have to add some features with many tables and new relations to this project.
How can I apply these tables and their relations to the Database without adding manually?
Is there any way to use Add-Migratiosn and Update-Database to apply new changes via EF core instead of manually applying?

If you have not many changes to your DBContext you can remove it and use Scaffolding to create new DbContext from the existing database schema. You can find more information in the official Microsoft documentation here.
It is better to use only one entity framework database approach either Database-First or Code-First.

Related

What to do when we need another table and a model for it, in case we have already applied the database first approach? (.NET Core, MVC)

Whether the steps are the same as for the first time? Is it good to use the -force command to change the old state?
Using Scaffold-DbContext command or dotnet ef dbcontext scaffold command could help generate code for a DbContext and entity types for an existing database.
If you'd like to generate entity types for specific tables, you can set -Tables <String[]> parameter, like below.

partial use of doctrine on an existing php project

I am a new developer on an existing php project that respect its proper mvc.
I have successfully "plug" a Symfony installation on it, in order to replace some of the already existing Symfony components such as Router, Request etc...
I have some functionalities to develop and I am isolating them under one bundle.
My question is : can I use Doctrine for this one in order to start a sanitize work on the existing database ? If I want to use foreign keys with the existing others tables I need to configure the mapping on them...It's a problem because I cannot start a refactoring for the objects of this project that are not entities-like. Is there a solution to use doctrine only for my bundle and keeping the use of foreign-keys, cascading etc... ?
Thank you for all
If you wish to only generate the entities for your isolated bundle, you can do it.
Check documentation: http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_doctrine_entity.html
Are you planning to create your tables in the same database or in a differente database?

How use migrations in ASP.net MVC Entity Framework using DB First

By using "Code First" model programming is possible to create migrations do update database schema.
Is possible to create migrations to update database schema using ASP.Net Entity Framework and "DB First"?
Is possible to somehow update database schema (without data loss)?
You can do "Code First from an existing database" if that's what you mean. Here's a walkthrough.
This will create models for you in C# based on the existing database design, it's basically a one-time setup. From there you can use it as if you were Code First all along.

Entity Framework Core - Scaffold existing database to one or group of class files

As stated in this tutorial, I can scaffold code-first EF Core from an existing database using Scaffold-DbContext in the Package Manager Console.
It's all good but my problem is that it scaffolds separate class files for each table and another for the context class. I find this a bit messy if I have too many tables.
I can rearrange it all by hand but Is there a way to scaffold everything to one class file? Or maybe having the context class on a separate file and then group the tables to another file per schema.
This behavior is not an option of EF Core scaffolding as of 1.0.0.

Validate EF Code first model against existing database

Is there a way to check that a DbContext matches the database when the database was not created by EF code first?
I am looking for similar functionality to Database.CompatibleWithModel but there is not metadata.
There is currently no way in EF to do this; however, you may be able to use the DDL script as a starting point for verifying that all the artifacts exist in the database. To get this script, use
string ddlScript = ((IObjectContextAdapter)myContext).ObjectContext.CreateDatabaseScript();
Some tools may be able to use this script to do a schema compare against your database. This will tell you if your model is compatible.
Have you tried using Entity Framework Power Tools.
you can use the tools to Reverse Engineer Code First - Generates POCO
classes, derived DbContext and Code First mapping for an existing
database.
And then maybe you can compare the reversed engineered information with what you already have.

Resources