EF Core 2:数据库优先与多对多(链接 table)

EF Core 2: Database first with many-to-many (linking table)

我的数据库中的项目和模型之间存在多对多关系

我正在使用此命令生成 .cs 模型:

Scaffold-DbContext "my connection string here" Microsoft.EntityFrameworkCore.SqlServer -OutputDir EFModels -Force -Context EFEntities -Tables Projects, Projects_Models, Models

在 EF6 中,这将创建 Project.ModelsModel.Projects 属性,而不会将 Projects_Models table 映射到它自己的 class.

但在这种情况下 (EF Core),它创建了一个 ProjectsModel class 和 Project.ProjectsModelsModel.ProjectsModels 属性。

如何才能使其表现得像在 EF6 中一样?

目前无法在 EF Core 中执行此操作,因为尚未添加该功能。来自 the docs:

Many-to-many relationships without an entity class to represent the join table are not yet supported. However, you can represent a many-to-many relationship by including an entity class for the join table and mapping two separate one-to-many relationships.