簡體   English   中英

如何在實體框架 6 中創建字段並從連接表中獲取數據

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

我正在使用 EF6 Code First 工作。 首先,我創建了 2 個類:

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 個表課程、標簽和標簽課程。 但是我在項目中沒有 TagCourse 課程。 我如何添加新字段,例如在 TagCourses 和 CRUD 上的詳細信息這個連接表?

可能對你有用

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; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM