As in previous versions of Entity Framework, is it possible in Entity Framework Core to reverse engineer only the selected tables of an existing database to create model classes out of them. This official ASP.NET site reverse engineers the entire database. In past, as shown in this ASP.NET tutorial, using old EF you could reverse engineer only the selected tables/Views if you chose to.
You use the DbContext Scaffold command to generate the model. The command has two required arguments - a connection string and a provider.
ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models.
The EF core only supports Code First & Database First approach. In Database First, We use the Scaffold-dbcontext to create the Model from an existing database. This is basically Reverse engineering the existing database. Once we create the entity classes databases first does not work.
One can solve the problem by usage of dotnet ef dbcontext scaffold command with multiple -t
(--table
) parameters. It allows to specify all the tables, which needed by imported (scaffolded). The feature is described initially here.
It is possible to specify the exact tables in a schema to use when scaffolding database and to omit the rest. The command-line examples that follow show the parameters needed for filtering tables.
.NET Core CLI:
dotnet ef dbcontext scaffold "server=localhost;port=3306;user=root;password=mypass;database=sakila" MySql.Data.EntityFrameworkCore -o sakila -t actor -t film -t film_actor -t language -f
Package Manager Console in Visual Studio:
Scaffold-DbContext "server=localhost;port=3306;user=root;password=mypass;database=sakila" MySql.Data.EntityFrameworkCore -OutputDir Sakila -Tables actor,film,film_actor,language -f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With