搭建现有数据库EF core 2.X后更新模型

时间:2019-01-18 01:00:27

标签: entity-framework-core

我正在使用EF core 2.X支架现有数据库。我已经使用“ dotnet ef dbcontext scaffold”命令生成了模型类,并且它生成了模型类。

数据库团队更改了一些表,我不得不再次运行“ dotnet ef dbcontext scaffold”命令来生成模型类以仅选择更改。

例如说 我有一个表叫做“ employee”,具有列ID,名称。

我运行“ dotnet ef dbcontext支架”来生成模型

此后,我更改了employee表,并在数据库中添加了另一列称为“ address”的地址。我如何只能使用脚手架命令来选择更改。

注意:我知道在生成模型之后,我应该使用迁移来更改数据库,但是不幸的是,我们的数据库团队已更改了数据库,但我必须这样做。和建议

1 个答案:

答案 0 :(得分:0)

您可以为scaffolding命令提供一个可选参数,以仅更新您定位的表。

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DirectoryNameOfYourModels -Tables employee -f

如果您使用的是.net core cli,请使用。

dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o DirectoryNameOfYourModels -t employee -f