简体   繁体   English

实体框架不会为多对多表创建模型实体

[英]Entity Framework does not create model entity for many to many tables

I have 3 tables: Job , Schedules and job_schedules which is the connection table, holding job_id and schedule_id for many to many connection. 我有3个表: JobSchedulesjob_schedules这是连接表,其中包含job_id和schedule_id用于多对多连接。 I currently use Entity Framework for importing the tables and creating the data model. 我目前使用实体框架导入表和创建数据模型。 The issue i'm facing is that when I import the job_schedules table, only a connection between job and schedules is made, no entity is defined in the model. 我面临的问题是,当我导入job_schedules表时,仅在job和schedules之间建立连接,而在模型中未定义任何实体。 How can I make the import create an entity in the model not just a many to many connection between the two tables? 如何使导入在模型中创建实体,而不仅仅是两个表之间的多对多连接?

I'm quite sure you can add the DbSet to your DataContext manualy. 我很确定您可以DbSetDbSet添加到您的DataContext You'll need the model itself: 您将需要模型本身:

[Table("tableName")]    
public class JobSchedule()
    {
        //yourproperties with [Column("Name")] atribute
    }

And the reference in the DbContext: 并在DbContext中引用:

DbSet<JobSchedule> JobSchedules = new DbSet<JobSchedule>()

And my advice is to use Migrations in the future, and the workflow will be much easier. 我的建议是将来使用迁移,这样工作流程将更加轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM