我们可以从现有数据库的选定表中搭建DbContext支架吗 [英] Can we Scaffold DbContext from selected tables of an existing database
问题描述
与先前版本的Entity Framework一样,在Entity Framework Core中是否可以仅对现有数据库的选定表进行反向工程以从中创建模型类.此ASP.NET官方网站对整个数据库进行反向工程.过去,如下所示,ASP.NET教程,如果您选择使用旧的EF,则只能对选定的表/视图进行反向工程.
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.
推荐答案
一个人可以通过使用此处.
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:
.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
Visual Studio中的Package Manager控制台:
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
这篇关于我们可以从现有数据库的选定表中搭建DbContext支架吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!