如何创建字段并从 Entity Framework 中加入的 table 获取数据 6

How to create field and get data from joined table in Entity Framework 6

我正在使用 EF6 Code First 工作。 首先我创建了 2 class:

public class Course
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection<Tag> Tags { get; set; }
}
public class Tag
{
    public int Id { get; set; }
    public string Name{ get; set; }
    public ICollection<Course> Courses { get; set; }
}

添加迁移和更新数据库后,我有 3 个 table 课程、标签和标签课程。但是我在项目中没有 TagCourse class。我如何添加新字段,例如加入的 TagCourses 和 CRUD 的详细信息table?

这个可能对你有用

public class Course
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection<TagCourse> TagCourses{ get; set; }
}

public class TagCourse
{
   public int CourseId {get;set; }
   public int TagId {get;set; }

   public string Details {get;set; }
}

public class Tag
{
    public int Id { get; set; }
    public string Name{ get; set; }
    public ICollection<TagCourse> TagCourses { get; set; }
}