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

时间:2018-03-22 23:40:45

标签: asp.net-core entity-framework-core ef-database-first ef-core-2.0

I have many-to-many relationship between Projects and Models in my database

Relationship diagram

I am using this command to generate the .cs models:

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

In EF6, this would create Project.Models and Model.Projects properties, without mapping the Projects_Models table into its own class.

But in this case (EF Core), it created a ProjectsModel class, and Project.ProjectsModels and Model.ProjectsModels properties instead.

How can you make it behave like it was in EF6?

1 个答案:

答案 0 :(得分:3)

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

  

尚不支持没有实体类来表示连接表的多对多关系。但是,您可以通过包含连接表的实体类并映射两个单独的一对多关系来表示多对多关系。

相关问题