我想知道使用EF Core数据库优先时是否存在处理迁移的标准方法。
每次更改数据库时,我都会在CLI中运行此命令:
dotnet ef dbcontext scaffold "Data Source=(local);Initial Catalog=myCatalog;Trusted_Connection=true;" Microsoft.EntityFrameworkCore.SqlServer -o Models -f
它的问题会覆盖我在其他实体和dbcontext中所做的每一个更改,例如,我为每个实体都具有一个Id
接口,当我进行脚手架安装时,我以后需要再次将其添加到该实体中,是否可能与数据库或仅与特定实体同步项目?
是的,您可以通过指定架构和表来限制对哪些表进行反向工程。
--schema
选项可用于包括架构中的每个表,而--table
可用于包括特定表。
[尝试如下,仅更新Foo
表。 Click here for more detail.
dotnet ef dbcontext scaffold "Data Source=(local);Initial Catalog=myCatalog;Trusted_Connection=true;" Microsoft.EntityFrameworkCore.SqlServer -o Models -f --table Foo