[英]How to create field and get data from joined table in Entity Framework 6
I'm using EF6 Code First to work.我正在使用 EF6 Code First 工作。 First I created 2 class:
首先,我创建了 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; }
}
After add-migration and update-database, I have 3 table Courses, Tags and TagCourses.在添加迁移和更新数据库之后,我有 3 个表课程、标签和标签课程。 But I dont have TagCourse class in project.
但是我在项目中没有 TagCourse 课程。 How can I add new fields like Details on TagCourses and CRUD this joined table?
我如何添加新字段,例如在 TagCourses 和 CRUD 上的详细信息这个连接表?
This might work for you这可能对你有用
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.