如何将 scaffold-dbcontext 到不同的文件夹?

how to scaffold-dbcontext to different folders?

我们可以运行以下将在项目中创建上下文和模型的命令:

Scaffold-DbContext -Connection "Data Source=somedatasource.com;Initial Catalog=mydb;Integrated Security=False;User Id=user;Password=pass;MultipleActiveResultSets=True" -Provider Microsoft.EntityFrameworkCore.SqlServer -Tables PrdSalesRegion -Context SalesRegionContext

我们如何为上下文和表指定不同的输出文件夹?

当我尝试这样做时:

Scaffold-DbContext -Connection "Data Source=somedatasource.com;Initial Catalog=mydb;Integrated Security=False;User Id=user;Password=pass;MultipleActiveResultSets=True" -Provider Microsoft.EntityFrameworkCore.SqlServer -Tables Models/PrdSalesRegion -Context Context/SalesRegionContext

请注意,唯一的变化是:

-Tables Models/PrdSalesRegion -Context Context/SalesRegionContext

然后我得到这个输出:

The context class name passed in, Context/SalesRegionContext, is not a valid C# identifier.

我们如何为上下文和表指定不同的输出文件夹?

您可以添加标志 -o <DIR>。您还可以使用 -f 标志覆盖现有文件,同时使用新字段更新现有模型。

完整的命令可以是:

Scaffold-DbContext "Host=127.0.0.1;Database=dbname;Username=postgres;Password=test12345"Npgsql.EntityFrameworkCore.PostgreSQL -o Entities -f

希望对您有所帮助